gridview 编辑删除:

 

 

前台代码:

<asp:GridView ID="GVUserType" runat="server" OnRowCancelingEdit="GVUserType_RowCancelingEdit"

                                OnRowEditing="GVUserType_RowEditing" OnRowUpdating="GVUserType_RowUpdating"

                                OnRowDeleting="GVUserType_RowDeleting" OnPageIndexChanging="GVUserType_PageIndexChanging"

                                DataKeyNames="userTypeId" AutoGenerateColumns="false" AllowPaging="True" AllowSorting="False"

                                GridLines="None" PagerSettings-PageButtonCount="5" PageSize="5">

                                <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />

                                <Columns>

                                    <asp:TemplateField HeaderText="用户权限" HeaderStyle-CssClass="userInfoTh2" ItemStyle-CssClass="userInfoItem">

                                        <EditItemTemplate>

                                            <asp:TextBox ID="txtUserType" runat="server" Text='<%#Eval("userType") %>'></asp:TextBox>

                                        </EditItemTemplate>

                                        <ItemTemplate>

                                            <asp:Label ID="lblUserType" runat="server" Text='<%#Eval("userType") %>'></asp:Label>

                                        </ItemTemplate>

                                    </asp:TemplateField>

                                    <asp:TemplateField HeaderText="编辑" HeaderStyle-CssClass="userInfoTh1" ItemStyle-CssClass="userInfoItem">

                                        <EditItemTemplate>

                                            <asp:LinkButton ID="lbUpdate" runat="server" CausesValidation="true" CommandName="Update"

                                                Text="更新"></asp:LinkButton>

                                            <asp:LinkButton ID="lbCancel" runat="server" CausesValidation="true" CommandName="Cancel"

                                                Text="取消"></asp:LinkButton>

                                        </EditItemTemplate>

                                        <ItemTemplate>

                                            <asp:LinkButton ID="lbEdit" runat="server" CausesValidation="true" CommandName="Edit"

                                                Text="编辑"></asp:LinkButton>

                                        </ItemTemplate>

                                    </asp:TemplateField>

                                </Columns>

                                <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />

                                <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="right" />

                                <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />

                                <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" CssClass="userInfo"

                                    HorizontalAlign="Center" VerticalAlign="Middle" />

                                <AlternatingRowStyle BackColor="#F7F7F7" />

                            </asp:GridView>

 

后台代码:

Protected Sub GVUserType_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GVUserType.PageIndexChanging

        GVUserType.PageIndex = e.NewPageIndex

        bindUserType()

    End Sub

 

    Protected Sub GVUserType_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GVUserType.RowCancelingEdit

        '取消编辑

        GVUserType.EditIndex = -1

        bindUserType()

    End Sub

 

    Protected Sub GVUserType_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GVUserType.RowDeleting

 

    End Sub

 

    Protected Sub GVUserType_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GVUserType.RowEditing

        '进入编辑状态

        GVUserType.EditIndex = e.NewEditIndex

        bindUserType()

    End Sub

 

    Protected Sub GVUserType_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GVUserType.RowUpdating

        '编辑信息,更新信息

      

        Dim myUserType As New UserType

        Dim bool As Boolean

 

        myUserType.userType = CType((GVUserType.Rows(e.RowIndex).Cells("0").FindControl("txtUserType")), TextBox).Text.ToString

        myUserType.userTypeId = Convert.ToInt64(GVUserType.DataKeys(e.RowIndex).Value.ToString)

 

        '判断用户权限是否已经存在

        If BuserType.IsNameExist(myUserType.userType) Then

            MsgBox("用户权限已经存在!")

            Exit Sub

        End If

 

        bool = BuserType.UpdateUserType(myUserType)

 

        GVUserType.EditIndex = -1

        bindUserType()

 

        If bool Then

            MsgBox("更新成功!")

        Else

            MsgBox("更新失败!")

        End If

End Sub

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值