这是一句范例:
string str1 = ((TextBox)e.Item.Cells[0].FindControl("edit_classroom_name")).Text ;请问:
1、上句中的 Cells[0] 是什么意思?为什么 Cells[0]改为Cells[1]显示结果也是一样的?
2、另外一句范例,少了Cells[0],运行结果却是一样的,请告知他们的不同之处?为什么结果又是一样的?
string str2 = ((TextBox)e.Item.FindControl("edit_classroom_name")).Text;

解决方案 »

  1.   

    Cells[0] 表示第一列(隐藏的列也计数)。一般直接用 
    string str2 = ((TextBox)e.Item.FindControl("edit_classroom_name")).Text;
    就可以了。
      

  2.   

    结果一样是因为,都是通过FindControl()这个方法去实现查找相应的WEB控件,如果指定了cell哪就在相应的列中去查找对应控件,如果不指cell就在整个Grid中查询,所以结果是一样的
      

  3.   

    FindControl()方法查找控件
    e.Item是指该行
    e.Item.Cells[x]指该行该列
    FindControl("ID") ID是要查找的控件ID有无 Cells[x]是一样的,因为即使没有指定列也能找到控件