现在的位置: 首页 > 综合 > 正文

在DatailsView控件删除操作中添加确认询问.

2012年05月20日 ⁄ 综合 ⁄ 共 1278字 ⁄ 字号 评论关闭
 
 DetailsView 控件能够自动绑定到任何数据源控件,使用其数据操作集。控件能够自动分页、更新、插入和删除底层数据源的数据项.如何在删除操作中添加确认询问呢,下面的代码是种方法.


    
Protected Sub GridView1_ItemCreated(ByVal sender As ObjectByVal e As System.EventArgs) Handles GridView1.ItemCreated
        
' 检查页脚行是否存在
        If Not (GridView1.FooterRow Is NothingThen

            '检查是否有行在DatailViews中存在
            If GridView1.Rows.Count = 0 Then Exit Sub
            
'Command bar在最后的最后一行
            Dim commandRowIndex As Integer = GridView1.Rows.Count - 1

            Dim commandRow As DetailsViewRow = GridView1.Rows(commandRowIndex)

            '查找 DELETE 按钮
            Dim cell As DataControlFieldCell = CType(commandRow.Controls(0), DataControlFieldCell)
            
Dim ctl As Control
            
For Each ctl In cell.Controls
                
'检查找到的控件时候是LinkButton
                If ctl.ToString = "System.Web.UI.WebControls.DataControlLinkButton" Then

                    Dim link As LinkButton = ctl '
                    If Not (link Is NothingThen
                        
If link.CommandName = "Delete" Then
                            link.ToolTip 
= "删除操作"
                            link.OnClientClick 
= "return confirm('你是否确定删除这条记录?');"
                        
End If
                    
End If
                
End If
            
Next
        
End If
    
End Sub

抱歉!评论已关闭.