当前位置: 代码迷 >> ASP.NET >> gridview checkbox 有关问题 c#net 急
  详细解决方案

gridview checkbox 有关问题 c#net 急

热度:9200   发布时间:2013-02-26 00:00:00.0
gridview checkbox 问题 c#.net 急!
protected   void   GridView1_RowDataBound(object   sender,   GridViewRowEventArgs   e)
        {

                if   (e.Row.RowType   ==   DataControlRowType.DataRow)
                {
                     
                        ((CheckBox)e.Row.Cells[2].FindControl( "chk ")).Checked   =   true;                    
                   
                }

        }
这是绑定事件,为什么会提示未实例话对象呢????


------解决方案--------------------------------------------------------
没找到控件,e.Row.Cells[2].---表示第3个哟
------解决方案--------------------------------------------------------
e.Row.Cells[2].FindControl( "chk ") 应该是这个没找到,检查一下
------解决方案--------------------------------------------------------
e.Row.Cells[2].FindControl( "chk ")

不是cells[2]不对,就是chk  的id不对了。
------解决方案--------------------------------------------------------
使用前最好先判断

if(e.Row.Cells[2].FindControl( "chk ")!=null)
{
((CheckBox)e.Row.Cells[2].FindControl( "chk ")).Checked = true;
}
------解决方案--------------------------------------------------------
动态加的话打开HTML的源文件看看这个CHECKBOK的ID是不是 "chk "
------解决方案--------------------------------------------------------
FindControl( "chk ")改成control[1]
你是要做全选吗
foreach (GridViewRow thisrow in GridView1.Rows)
{
((CheckBox)thisrow.Cells[2].Controls[1]).Checked = true;
}
  相关解决方案