如何获取datagrid中的模版列的头部的子控件的引用?
不知道我说清楚了没有?比如我头部放置了一个CheckBox,怎样用形如这样的语句获取实例的引用?
CheckBox ck = (CheckBox )Item.FindControl("ckbItem"); Item如何直接定位到datagrid最顶端的Item。。

解决方案 »

  1.   

    ItemDataBounded事件中if(e.ItemType==ListItemType.Header)
    {
      e.Item.Cells[0].FindControl("xxx");
    }
      

  2.   

    但是这样遍历出来的不利于我实现,我是要做一个全选和反选功能。如果最顶端的checkbox选中,则下面的都选中,反之亦然。
    if(((CheckBox)dgCheckItem.FindControl("checkall")).Checked==true)
    {
    foreach(DataGridItem Item in this.dgCheckItem.Items)
    {
    ckbItem = (CheckBox)Item.FindControl("ckbItem");
    ckbItem.Checked = true;
    }
    }
      

  3.   

    if(((CheckBox)dgCheckItem.FindControl("checkall")).Checked==true)
    {
      foreach(DataGridItem Item in this.dgCheckItem.Items)
      {
        ckbItem = (CheckBox)Item.FindControl("ckbItem");
        ckbItem.Checked = true;
      }
    }
      

  4.   

    全选这种还是用javascript比较好,可以减少刷新