我在datagrid控件中的每一行加入了一个Textbox控件,这个控件是用来输入一些字符,在提交时我怎么取到datagrid中每一行的textbox控件里的值,非常着急,望高手指点!!!多谢!!!

解决方案 »

  1.   

    foreach(DataGridItem dgi in MyDataGrid1.Items)
    {
    TextBox txt = (TextBox)dgi.FindControl("TextBox的id");
    if (txt != null)
    string str=txt.Text.ToString();
    }
      

  2.   

    foreach(DataGridItem dgi in yourDataGrid.Items)
    {
        TextBox tb = (TextBox)dgi.FindControl("yourTextBoxID");
        tb.Text......
    }
      

  3.   

    private void Button1_Click(object sender, System.EventArgs e)
    {

    string sMainProjectID;

    foreach(DataGridItem oDataGridItem in oDataGrid.Items )
                            //oDataGrid为你的datagride的ID
    {
    CheckBox oCheckBox  =(CheckBox)oDataGridItem.FindControl("mycheck");
    TextBox oCheckBox  =(TextBox)oDataGridItem.FindControl("youtextboxid");
    sMainProjectID = oCheckBox.text;}
    //
    }
      

  4.   

    foreach(DataGridItem dgi in MyDataGrid1.Items)
    {
    TextBox txt = (TextBox)dgi.FindControl("TextBox的id");
    if (txt != null)
    string str;
                      str = txt.Text.ToString();
                      Response.Write("ok:" + str); }
    我这样写了,还是不行,没把里面的值取到,请多指教!
      

  5.   

    你把你的代码贴出来看看,包括HTML的
      

  6.   

    我是这样写的,麻烦帮我看看,我不知问题出在哪里?:private void Page_Load(object sender, System.EventArgs e)
    {OracleConnection myConnection = new OracleConnection(ConfigurationSettings.AppSettings["human"]);
    OracleDataAdapter myCommand = new OracleDataAdapter("select * from wz_dept_emp where emp_no = '1914'", myConnection);
    DataSet ds = new DataSet();
    myCommand.Fill(ds, "wz_dept_emp");
    MyDataGrid.DataSource=ds.Tables["wz_dept_emp"].DefaultView;
                         MyDataGrid.DataBind();
    }
    private void btnquery_Click(object sender, System.EventArgs e)
    {foreach(DataGridItem dgi in MyDataGrid.Items)
    {TextBox txt = (TextBox)dgi.FindControl("TextBox1");
    if (txt != null)
    Response.Write("ok:" + txt.Text);
    }}------------------------------
    你的数据绑定有问题
    如下:private void Page_Load(object sender, System.EventArgs e)
    {
        if(!Page.IsPostBack)
        {
               OracleConnection myConnection = new OracleConnection(ConfigurationSettings.AppSettings["human"]);
    OracleDataAdapter myCommand = new OracleDataAdapter("select * from wz_dept_emp where emp_no = '1914'", myConnection);
    DataSet ds = new DataSet();
    myCommand.Fill(ds, "wz_dept_emp");
    MyDataGrid.DataSource=ds.Tables["wz_dept_emp"].DefaultView;
                         MyDataGrid.DataBind();
         }
    }
      

  7.   


    ----------------------------------------------------------------
    原贴内容:
    ----------------------------------------------------------------
    原贴内容:
    ----------------------------------------------------------------
    非常好,按照你的方法问题已经解决了,非常非常感谢!!!再想问一下,为什么要这样?如果你的Page_Load里面没有这个判断
    点击Button
    页面PostBack
    又重新获取数据
    就把你输入的数据冲掉了
    如此而已
      

  8.   

    ((TextBox)e.item.cell["所在的列"].controls[1]).text
    (TextBox)dgi.FindControl("TextBox");