我有一个datalist,在edit模板里面有一个checkboxlist控件。
我想在点击编辑按钮的时候找到这个控件,但是老是说我没有引用
private void RolesList_ItemCommand(object sender, DataListCommandEventArgs e)
{
   if(e.CommandName == "edit)
    {
      CheckBoxList ck=(CheckBoxList)e.Item.FindControl("chkPopedom1");
    }
}

解决方案 »

  1.   

    RolesList_ItemCommand
    事件错了

    RolesList_EditCommand
      

  2.   

    不是,我在这里用commandname来区别了。
    private void RolesList_ItemCommand(object sender, DataListCommandEventArgs e)
    {
       if(e.CommandName == "edit)
        {
          rolesList.EditItemIndex = e.Item.ItemIndex;
          BindData();
          CheckBoxList ck=(CheckBoxList)e.Item.FindControl("chkPopedom1");
        }
    }
      

  3.   

    commandname是不会触发如edit,delete等命令的。
    用editcommand把
      

  4.   

    你的数据绑定在Page_Load中的!IsPostBack中写
      

  5.   

    谢谢,搞定了。是ItemCommand、itemcreate、itemdatabound三者之间的执行顺序上。