asp.net中gridview中标题和项目复选框的默认选择
我有带有标题和项目复选框的gridview。当我选中标题复选框时,我的代码可以选中所有项目复选框。当我取消选中标题复选框时,我的代码可以取消选中所有项目复选框 这里我的问题是当我的页面加载时(意味着网格第一次加载时),默认情况下应选中标题和项目复选框。我们如何做到这一点。在Gridview中使用事件asp.net中gridview中标题和项目复选框的默认选择,asp.net,Asp.net,我有带有标题和项目复选框的gridview。当我选中标题复选框时,我的代码可以选中所有项目复选框。当我取消选中标题复选框时,我的代码可以取消选中所有项目复选框 这里我的问题是当我的页面加载时(意味着网格第一次加载时),默认情况下应选中标题和项目复选框。我们如何做到这一点。在Gridview中使用事件 protected void GridViewName_RowDataBound(object sender, GridViewRowEventArgs e) { if (e
protected void GridViewName_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row .RowType == DataControlRowType .DataRow )
{
//Your Code
}
}
在网格视图中,列是这样写的
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="chkhead" runat="server" onclick="SelectAllCheckboxes(this)" ClientIDMode="Static" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chksub" runat="server" ClientIDMode="Static" />
</ItemTemplate>
</asp:TemplateField>
然后编写Java脚本函数选择所有复选框
// select all check boxes
function SelectAllCheckboxes(spanChk) {
// Added as ASPX uses SPAN for checkbox
var oItem = spanChk.children;
var theBox = (spanChk.type == "checkbox") ?
spanChk : spanChk.children.item[0];
xState = theBox.checked;
elm = theBox.form.elements;
for (i = 0; i < elm.length; i++)
if (elm[i].type == "checkbox" && elm[i].id != theBox.id) {
//elm[i].click();
if (!elm[i].disabled) {
if (elm[i].checked != xState)
elm[i].click();
}
//elm[i].checked=xState;
}
}
//选中所有复选框
功能选择所有复选框(spanChk){
//添加为ASPX使用SPAN作为复选框
var oItem=spanChk.儿童;
变量theBox=(spanChk.type==“复选框”)?
spanChk:spanChk.children.item[0];
xState=box.checked;
elm=box.form.elements;
对于(i=0;i
写入.cs页面加载事件后,首先绑定网格视图并chheader.checked=true强>