前台代码:
<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