我想通过单击一个按钮一次更新GridView的所有行: ASPX:
</asp:ObjectDataSource>
<asp:ListBox ID="ListBoxRoles" runat="server" DataSourceID="ObjectDataSourceAllRoles"
AutoPostBack="true" DataTextField="RoleName" DataValueField="RoleID"
OnSelectedIndexChanged="ListBoxRoles_SelectedIndexChanged">
</asp:ListBox>
<asp:ObjectDataSource ID="ObjectDataSourceRolePermissions" runat="server"
TypeName="RolePermission" SelectMethod="GetRolePermissionByRoleID"
UpdateMethod="UpdateRolePermission">
<SelectParameters>
<asp:ControlParameter ControlID="ListBoxRoles" Name="RoleID" PropertyName="SelectedValue"
Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:ControlParameter ControlID="ListBoxRoles" Name="RoleID" PropertyName="SelectedValue"
Type="String" />
</UpdateParameters>
</asp:ObjectDataSource>
<asp:GridView ID="GridViewRolePermission" SkinID="GridViewSecurity" runat="server" style="width: 100%;"
HeaderStyle-Height="50" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="ObjectDataSourceRolePermissions">
<Columns>
<asp:BoundField ItemStyle-HorizontalAlign="Center" DataField="PermissionName" SortExpression="PermissionName" />
<asp:TemplateField ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox ID="CheckBoxRead" runat="server" Checked='<%#Bind("Read") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox ID="CheckBoxUpdate" runat="server" Checked='<%#Bind("Update") %>' />
</ItemTemplate>
</asp:TemplateField>
</asp:GridView>
<asp:Button runat="server" ID="ButtonUpdateRolePermissions" Text="Save" OnClick="ButtonUpdateRolePermissions_Click" />
我想在点击ButtonUpdateRolePermissions后更新gridview的所有行。 我试过了:
protected void ButtonupdateRolePermissions_Click(object sender, EventArgs e)
{
foreach(GridViewRow RolePermission in this.GridViewRolePermission.Rows)
{
this.ObjectDataSourceRolePermissions.Update();
}
}
但更新方法不考虑更新和读取字段。