【发布时间】:2011-04-27 02:36:21
【问题描述】:
我有一个用户控件“SettingsControl”,其中包含一个 ajax:CollapsiblePanelExtender,它又具有一个 GridView (gridView) 和复选框。在 GridView 之上,我们有两个链接按钮“全选”和“全部清除”。我已经写了启用全选并清除所有功能。全选应该通过调用编写在客户端 .aspx 文件上的以下 JavaScript 来选择网格中的所有行。
function SelectAll(chk)
{
//get reference of GridView control
var grid = document.getElementById('<%= SettingsControl1.FindControl("gridView").ClientID %>');
//variable to contain the cell of the grid
var cell;
if (grid.rows.length > 0)
{
//loop starts from 1. rows[0] points to the header.
for (i=1; i<grid.rows.length; i++)
{
//get the reference of first column
cell = grid.rows[i].cells[0];
//loop according to the number of childNodes in the cell
for (j=0; j<cell.childNodes.length; j++)
{
//if childNode type is CheckBox
if (cell.childNodes[j].type =="checkbox" && cell.childNodes[j].id.indexOf('chkSel')!=-1)
{
//assign the status of the Select All checkbox to the cell checkbox within the grid
cell.childNodes[j].checked = chk;
}
}
}
}
}
我无法在客户端访问用户控件或用户控件的任何元素。我不确定如何实现此功能。
.aspx 页面将用户控件调用为:
<uc1:SettingsControl ID="SettingsControl1" runat="server" />
请帮忙!!!!
【问题讨论】:
标签: javascript gridview checkbox controls