string aa = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim();无法将类型为“System.Web.UI.LiteralControl”的对象强制转换为类型“System.Web.UI.WebControls.TextBox”。异常点更新的时候获取不到要更新的文本框的值 索引不到那个控件 谁能帮下?

解决方案 »

  1.   

    应该是你是直接用的boundfield,这样的话GridView1.Rows[e.RowIndex].Cells[1].innerText应该可以取到值
      

  2.   

    string aa = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim(); Controls[0] 不是TextBox 控件是Label控件 试下Controls[1]
      

  3.   

    string aa ="";
     System.Web.UI.WebControls.TextBox txt_a = GridView1.Rows[e.RowIndex].Cells[1].findControl("控件ID") as System.Web.UI.WebControls.TextBox;
     if(txt_a !=null)
    {
       aa = txt_a.Text.Trim();
    }
      

  4.   

    GridView1.Rows.FindContral("TextBoxName");找TextBox
      

  5.   


    换成1我索引到了前面的按钮  异常button不能转换为Textbox
    另回复1楼  也没有innerText属性啊
      

  6.   

    string aa =""; 
    System.Web.UI.WebControls.TextBox txt_a = GridView1.Rows[e.RowIndex].Cells[1].findControl("控件ID") as System.Web.UI.WebControls.TextBox; 
    if(txt_a !=null) 

      aa = txt_a.Text.Trim(); 
    }上面的代码你试试,应该没问题!
      

  7.   


    不行啊 数据是我从数据库里查询出来的 也不知道叫什么名 GridView控件的ID我也试验了 都不行help!
      

  8.   

    把你的updating事件代码整个贴出来,
      

  9.   

    已经搞定了 string aa = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim(); 我的那个控件Cells索引跑到3去了 不知道怎么搞的 不过还是谢谢大家了
      

  10.   

    for (int i = 0; i < this.GridView1.Rows.Count; i++)
    {
                int nTag = Convert.ToInt32(this.GridView1.Rows[i].Cells[0].Text);     绑定列取值
                TextBox txtName = (TextBox)this.GridView1.Rows[i].FindControl("txtTagName");TextBox取值   
    }