GridView中点击删除按钮弹出对话框

 点击删除按钮弹出对话框:

 

< asp:GridView ID = " TopicView "  Width = " 100% "  runat = " server "  AutoGenerateColumns = " False "
                    BorderColor
= " #3B6BD1 "  BorderWidth = " 1px "  BackColor = " White "  
                    CellPadding
= " 4 "  OnRowDataBound = " TopicView_RowDataBound "  OnRowDeleting = " TopicView_RowDeleting "  OnRowCommand = " TopicView_RowCommand "  CssClass = " GbText " >
                    
< FooterStyle ForeColor = " #330099 "  BackColor = " #FFFFCC " ></ FooterStyle >
                    
< SelectedRowStyle Font - Bold = " True "  ForeColor = " #663399 "  BackColor = " #FFCC66 "  BorderColor = " CornflowerBlue "   />
                    
< RowStyle ForeColor = " #330099 "  BackColor = " White "  BorderColor = " CornflowerBlue "  BorderStyle = " Solid " />
                    
< HeaderStyle Font - Bold = " True "  ForeColor = " #FFFFCC "  CssClass = " GbText "  BackColor = " #3B6BD1 " ></ HeaderStyle >     
                
< Columns >
                    
< asp:TemplateField HeaderText = " 主题名称 " >
                        
< ItemTemplate >
                            
<% #DataBinder.Eval(Container.DataItem, " Name " %>
                        
</ ItemTemplate >
                        
< ItemStyle HorizontalAlign = " Center "   />
                        
< HeaderStyle Width = " 20% "   />
                    
</ asp:TemplateField >
                    
< asp:TemplateField  HeaderText = " 详细说明 " >
                        
< ItemTemplate >
                            
<% # DataBinder.Eval(Container.DataItem, " Body " %>
                        
</ ItemTemplate >
                        
< ItemStyle HorizontalAlign = " Left "   />
                        
< HeaderStyle Width = " 50% "   />
                    
</ asp:TemplateField >
                    
< asp:TemplateField HeaderText = " 当前主题 " >
                        
< ItemTemplate >                             
                            
< asp:RadioButton ID = " IsCurrent "  ForeColor = " red "  BackColor = ' <%# (bool)DataBinder.Eval(Container.DataItem,"IsCurrent") ? Color.Blue : Color.White %> '   GroupName = " TopicGroup "  Enabled = " false "  runat = " server "  Checked = ' <%# DataBinder.Eval(Container.DataItem,"IsCurrent") %> '   />
                        
</ ItemTemplate >
                        
< ItemStyle HorizontalAlign = " Center "   />
                        
< HeaderStyle HorizontalAlign = " Center "  Width = " 10% "   />
                    
</ asp:TemplateField >
                    
< asp:TemplateField HeaderText = " 用户操作 " >
                        
< ItemTemplate >
                            
< a href = ' UpdateTopic.aspx?TopicID=<%#DataBinder.Eval(Container.DataItem,"TopicID") %> ' > 编辑 </ a >& nbsp; & nbsp; & nbsp;
                            
<asp:ImageButton ID="DeleteBtn" runat="server" CommandName="delete" ImageUrl="~/Images/delete.gif" AlternateText="删除该主题" CommandArgument='<%# DataBinder.Eval(Container.DataItem,"TopicID") %>' />
                        
</ ItemTemplate >
                        
< ItemStyle HorizontalAlign = " Center "   />
                        
< HeaderStyle Width = " 20% "   />
                    
</ asp:TemplateField >                     
                
</ Columns >
                    
< AlternatingRowStyle BorderColor = " CornflowerBlue "   />
                
</ asp:GridView >

 

protected   void  TopicView_RowDataBound( object  sender,GridViewRowEventArgs e)
    
{
        ImageButton deleteBtn 
= (ImageButton)e.Row.FindControl("DeleteBtn");
        
if(deleteBtn != null)
        
{
            deleteBtn.Attributes.Add(
"onclick","return confirm('你确定要删除所选择的数据项吗?');");
        }

    }

    
protected   void  TopicView_RowCommand( object  sender,GridViewCommandEventArgs e)
    
{
        
if(e.CommandName == "delete")
        
{
            
try
            
{   ///删除数据
                ITopic topic = new Topic();
                topic.DeleteTopic(Int32.Parse(e.CommandArgument.ToString()));

                
///重新绑定控件的数据
                BindTopicData();
                Response.Write(
"<script>alert('" + "删除数据成功,请妥善保管好你的数据!" + "');</script>");
            }

            
catch(Exception ex)
            
{   ///跳转到异常错误处理页面
                Response.Redirect("ErrorPage.aspx?ErrorMsg=" + ex.Message.Replace("<br>","").Replace(" ","")
                    
+ "&ErrorUrl=" + Request.Url.ToString().Replace("<br>","").Replace(" ",""));
            }

        }

    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值