报错:行 107:        {
行 108:                //取得表的主键
行 109:                string a = this.GridView1.DataKeys[e.RowIndex].Values[0].ToString();
行 110:
行 111:                //取得对应的字符串
我的代码如下:
                string a = this.GridView1.DataKeys[e.RowIndex].Values[0].ToString();
                string b = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[0].Controls[0]).Text.ToString();
              string c = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text.ToString();

解决方案 »

  1.   

        a,b,c分别代表的字段名如下`            public string a = "学校编号";
            public string b = "学校名称";
            public string c = "学校地址";
      

  2.   


     for (int i = 0; i < GridView1.Rows.Count; i++)
            {
             string a =  GridView1.DataKeys[i].Value.ToString()
            }
      

  3.   

    用datakey前要判断该行是不是header吧,大概是这样
    if (e.Row.RowType != RowType.Header )
      

  4.   

    把ButtonField加一个属性CommandName="aaa",然后用
    if (e.CommandName == "aaa")
            {
               string a = this.GridView1.DataKeys[e.RowIndex].Values[0].ToString(); 
               string b = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[0].Controls[0]).Text.ToString(); 
               string c = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text.ToString();        
            }看这样行不行
      

  5.   

    谢谢各位``
    问题已经解决了`
    只要在GridView列表属性的DataKeyNames项里添加所设为主键的字段名就可以`