[asp.net]如何做到grid的刪除功能

  • 1407
  • 0

摘要:[asp.net]如何做到grid的刪除功能

在aspx.vb端


Protected Sub gvMain_RowCommand(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvMain.RowCommand
        If e.CommandName = "DelJobRate" Then
            Dim strEffdate As String = e.CommandArgument

            Dim dt As DataTable
            dt = CType(Session("dt"), DataTable)
            Dim dr() As DataRow = dt.Select("effdate=" & strEffdate)
            If dr.Length > 0 Then
                dt.Rows.Remove(dr(0))
            End If

            Session("dt") = dt

            gvMain.DataSource = dt
            gvMain.DataBind()
           
        End If
    End Sub

在aspx端的gridview裡面


<asp:TemplateField ItemStyle-Width="1%">
                                            <ItemTemplate>
                                                <asp:ImageButton ID="ibtnDel" runat="server" CommandName="DelJobRate" CommandArgument='<%# Eval("effdate") %>' ImageUrl="~/Images/Delete.gif" />                                                
                                            </ItemTemplate>
                                        </asp:TemplateField>