How can I put CheckBox in WebGrid's header, in order to realize check all or check no?
Hello,You can use the template columns and put the check box into header and cell Please take a look at the sample code below:
<igtbl:TemplatedColumn> <CellTemplate> <asp:CheckBox ID="CheckBox1" runat="server" /> </CellTemplate> <HeaderTemplate> <asp:CheckBox ID="CheckBox2" runat="server" /> </HeaderTemplate> </igtbl:TemplatedColumn>
Hope this helps.
Thanks your answer. But I found it wasn't right by your advice. Why? I run the program and didn't find the checkbox display in the header. The code of page is below:
<igtbl:TemplatedColumn BaseColumnName="ReceiveState" Key="ReceiveState" DataType="System.Boolean" Type="CheckBox"> <Header Caption="接收" /> <HeaderStyle HorizontalAlign="center" /> <CellStyle HorizontalAlign="center" /> <HeaderTemplate> <asp:CheckBox ID="cbAll" runat="server" /> </HeaderTemplate></igtbl:TemplatedColumn>
Insead of templated column, we can go with normal check box type column. And for this check box column header text we can have the below text:
<div><input type = 'checkbox' name = 'cbSelectAll' checked='checked' onclick='SelectAll();'></div>
Write a simple javascript function to read the check box values from individual rows and set the corresponding value in check box 'cbSelectAll'
Best Regards,
Vijay