我用下面的方法隐藏列:BoundColumn col;
DataGrid1.AutoGenerateColumns=false;
try
{
string str="";
int x=0;
x=arraylist.Count;
for(int y=0;y<x;y++)
{
str=arraylist[y].ToString();
col = new BoundColumn();
col.HeaderText=str; 
col.DataField=str;
DataGrid1.Columns.Add(col);

}
}
catch
{

}SqlDataAdapter  sqlda=new SqlDataAdapter (strsql,sqlcnn);
sqlcnn.Open ();
DataSet ds=new DataSet ();  
sqlda.Fill (ds);
DataView dv=new DataView (ds.Tables[0]);
DataGrid1.DataSource =dv;
Cache["mydv"]=dv; //加入dv 到页面缓冲,用于二次检索
Cache["mydv2"]=dv;
DataGrid1.DataBind ();
DataGrid1.Columns[4].Visible=false;
DataGrid1.Columns[5].Visible=false;
                DataGrid1.Columns[8].Visible=false;
sqlcnn.Close ();                为什么在编辑按钮中用e.Item.Cells[5].Text报错说超出index,各位大侠帮帮我吧!

解决方案 »

  1.   

    第五列是也处在编辑状态.
    DataGrid1.Columns[5].ReadOnly= true;
      

  2.   

    其实我在编辑按钮里只是想把当前选中的记录的每列的值取出来显示,并没有去编辑啊!以前没有用DataGrid1.AutoGenerateColumns=false;没有报错!
      

  3.   

    第五列是也处在编辑状态.
    DataGrid1.Columns[5].ReadOnly= true;
    没有ReadOnly这个属性啊
      

  4.   

    试试看e.Item.Cells[4].Text因为索引是从0开始的
      

  5.   

    我的列有9列呀,怎么也不会操出范围,是不是设了DataGrid1.AutoGenerateColumns=false,不能用cell取值了