无法使用javascript在用户控件中访问子控件

时间:2010-10-18 18:36:05

标签: javascript gridview checkbox controls

我有一个包含ajax的用户控件“SettingsControl”:CollapsiblePanelExtender,它又有一个GridView(gridView)和checkBoxes。在GridView之上,我们有两个LinkBut​​tons“Select All”和“Clear All”。我写了启用全选并清除所有功能。选择全部应通过调用客户端.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;
                }
            }
        }
    }
}

我无法在客户端访问usercontrol或用户控件的任何元素。我不知道如何实现这一功能。

.aspx页面将用户控件命名为:

<uc1:SettingsControl ID="SettingsControl1" runat="server" />

请帮助!!!!

1 个答案:

答案 0 :(得分:0)

var grid = document.getElementById('SettingsControl1_gridView');

为我做了诀窍。

如果您在用户控件中执行脚本,则必须使用'SettingsControl1$gridView'

希望这可以帮助任何人......随时...; - )

相关问题