dataview的編輯,更新,刪除,取消等事件

本文介绍了一个使用ASP.NET中的GridView控件实现编辑和删除功能的例子。通过代码展示了如何响应编辑和删除操作,并对GridView控件的各项属性进行了详细配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

html 文件:
 <asp:GridView ID="GVA" runat="server" AutoGenerateColumns="False" BackColor="White"
            BorderColor
="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="0" CellSpacing="1"
            GridLines
="Horizontal" Style="font-size: 11pt; text-align: center">
            
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
            
<Columns>
                
<asp:BoundField DataField="c0" HeaderText="類別" />
                
<asp:BoundField DataField="c1" HeaderText="名稱" />
                
<asp:BoundField DataField="c2" HeaderText="數目" />
                
<asp:CommandField ShowEditButton="True" />
                
<asp:CommandField ShowDeleteButton="True" />
            
</Columns>
            
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
            
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
            
<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
            
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
            
<AlternatingRowStyle BackColor="#F7F7F7" />
        
</asp:GridView>

code:
 Protected Sub GVA_RowEditing(ByVal sender As ObjectByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GVA.RowEditing

        GVA.EditIndex 
= e.NewEditIndex
        fail_gv(
"682")
        
Dim i As Integer
        
For i = 0 To GVA.Rows.Count - 1
            
CType(GVA.Rows(i).Cells(3).Controls(0), LinkButton).Attributes.Add("onclick""var e=window.confirm('更新嗎?');if(e){return true;}else{return false;}")
        
Next
    
End Sub


    
Protected Sub GVA_RowCancelingEdit(ByVal sender As ObjectByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GVA.RowCancelingEdit
        
Me.GVA.EditIndex = -1
        fail_gv(
"682")
        
Dim i As Integer
        
For i = 0 To GVA.Rows.Count - 1
            
CType(GVA.Rows(i).Cells(3).Controls(0), LinkButton).Attributes.Add("onclick""var e=window.confirm('編輯11嗎?');if(e){return true;}else{return false;}")
        
Next
    
End Sub



    
Protected Sub GVA_RowUpdating(ByVal sender As ObjectByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GVA.RowUpdating
        
Me.GVA.EditIndex = -1
        fail_gv(
"682")
        
Dim i As Integer
        
For i = 0 To GVA.Rows.Count - 1
            
CType(GVA.Rows(i).Cells(3).Controls(0), LinkButton).Attributes.Add("onclick""var e=window.confirm('編輯12嗎?');if(e){return true;}else{return false;}")
        
Next
    
End Sub


    
Protected Sub GVA_RowDeleting(ByVal sender As ObjectByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GVA.RowDeleting
        GVA.EditIndex 
= -1
        fail_gv(
"682")
        
'Dim i As Integer
        'For i = 0 To GVA.Rows.Count - 1
        '    CType(GVA.Rows(i).Cells(3).Controls(0), LinkButton).Attributes.Add("onclick", "var e=window.confirm('更新嗎?');if(e){return true;}else{return false;}")
        'Next
    End Sub
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值