Gridview with checkboxes
I am searching for a example of gridview which has checkbox on each row and on header [Check ALL]. It should maintain the check on paging and when clicked on 开发者_如何学GoCheck all it should check all the checkboxes on all the pages.
Any help?
Use a template field, and in that template field use a header template: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.templatefield.headertemplate.aspx
You can use template field for that...just do not mention any thing in header template and in item template use
<asp:CheckBox runat=server id=chkBox1>
For selection through page u must know the Column no of the grid where u r placing Check boxes
foreach (gridviewRow variable in gridview name.rows)
{
// find the check box and set the Checked = true
}
you can use this javascript method
<script language="javascript" type="text/javascript">
function SelectAll(spanChk,grdClientID) {
var IsChecked = spanChk.checked;
var Chk = spanChk;
Parent = document.getElementById(grdClientID);
var items = Parent.getElementsByTagName('input');
for(i=0;i<items.length;i++)
{
if(items[i].type=="checkbox")
{
items[i].checked=document.getElementById(spanChk).checked;
}
}
}
</script>
<HeaderTemplate>
<asp:CheckBox runat="server" ID="chkHeader" onclick="SelectAll('<%=chkHeader.ClientID %>, <%=yourGrid.ClientID %>') />
</HeaderTemplate>
Use GridView templates to modify the layout of your grid view...
Refer to the following links for your case:
http://forums.asp.net/p/1473431/3418598.aspx
https://web.archive.org/web/20210728070916/https://www.4guysfromrolla.com/articles/053106-1.aspx
精彩评论