【发布时间】:2010-11-26 15:00:16
【问题描述】:
我在 aspx 页面的 DataGrid 中有一个 Header CheckBox,它用于选择 DataGrid 中的所有列,DataGrid 项(包括 Checkbox)绑定到 SQL 数据,并在通过后面的代码选择标题复选框时更新。问题是在重新绑定数据源以反映更改为 SQL 数据后,Header CheckBox 在 DataBinding 和回发后取消检查。
有没有办法在代码后面切换标题复选框
数据网格
<asp:DataGrid ID="Grid" runat="server" PageSize="5" AllowPaging="True"
DataKeyField="ID" AutoGenerateColumns="False" CellPadding="4"
ForeColor="#333333" GridLines="None" OnPageIndexChanged="Grid_PageIndexChanged"
OnCancelCommand="Grid_CancelCommand" OnDeleteCommand="Grid_DeleteCommand"
OnEditCommand="Grid_EditCommand" OnUpdateCommand="Grid_UpdateCommand">
<Columns>
<asp:BoundColumn HeaderText="" DataField="ID" visible="False" > </asp:BoundColumn>
<asp:BoundColumn HeaderText="Process Name" DataField="ProcessName"> </asp:BoundColumn>
<asp:BoundColumn HeaderText="Step" DataField="Order"> </asp:BoundColumn>
<asp:BoundColumn HeaderText="Instructions" DataField="Instructions"> </asp:BoundColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox ID="cbRows" runat="server" Checked='<%# DataBinder.Eval(Container.DataItem, "Completed") %>' AutoPostBack="true" OnCheckedChanged= "Grid_Updatecheckbox" />
</ItemTemplate>
<HeaderTemplate >
<%--<asp:Button runat="server" ID="mainCB" onclick="CheckAll" Text="Chk"/>--%>
<%--<input type="checkbox" id="mainCB" runat = "server" onclick="javascript:CheckAll(this);" />--%>
<asp:Checkbox id="mainCB" AutoPostBack = "true" runat = "server" OnCheckedChanged="CheckAll" />
</HeaderTemplate>
</asp:TemplateColumn>
<asp:BoundColumn HeaderText="Completed" DataField="Completed"> </asp:BoundColumn>
<asp:EditCommandColumn EditText="Edit" CancelText="Cancel" UpdateText="Update" HeaderText="Edit"> </asp:EditCommandColumn>
<asp:ButtonColumn CommandName="Delete" HeaderText="Delete" Text="Delete"> </asp:ButtonColumn>
</Columns>
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<SelectedItemStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" Mode="NumericPages" />
<AlternatingItemStyle BackColor="White" />
<ItemStyle BackColor="#FFFBD6" ForeColor="#333333" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
</asp:DataGrid>
【问题讨论】: