如:
((TextBox)e.Item.FindControl("tbName")).Text
这是一个TextBox的控件的值 ,其它的控件是两样的道理!!

解决方案 »

  1.   

    private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    String updateCmd = "UPDATE tongxunlu SET name=@Name,hphone=@Hphone,ophone=@Ophone,mphone=@Mphone,danwei=@Danwei,adress=@Adress where id =@Id";
    SqlCommand myCommand = new SqlCommand(updateCmd, myConnection);

    myCommand.Parameters.Add(new SqlParameter("@Id", SqlDbType.Int, 4));
    myCommand.Parameters.Add(new SqlParameter("@Name", SqlDbType.Char));
    myCommand.Parameters.Add(new SqlParameter("@Hphone", SqlDbType.Char));
    myCommand.Parameters.Add(new SqlParameter("@Ophone", SqlDbType.Char));
    myCommand.Parameters.Add(new SqlParameter("@Mphone", SqlDbType.Char));
    myCommand.Parameters.Add(new SqlParameter("@Danwei", SqlDbType.Char));
    myCommand.Parameters.Add(new SqlParameter("@Adress", SqlDbType.Char));

    myCommand.Parameters["@Id"].Value = DataGrid1.DataKeys[(int)e.Item.ItemIndex];
    String[] cols = {"@Name","@Hphone","@Ophone","@Mphone","@Danwei","@Adress"};
    int numCols = e.Item.Cells.Count;
    for (int i=2; i<numCols; i++) //跳过第一、第二列
    {
    String colvalue =((TextBox)e.Item.Cells[i].Controls[0]).Text; myCommand.Parameters[cols[i-2]].Value = colvalue;
    }

    myCommand.Connection.Open();
    myCommand.ExecuteNonQuery();
    myCommand.Connection.Close(); 
    DataGrid1.EditItemIndex = -1;
    BindGrid();
    }
    }
      

  2.   

    // 取你编辑第一列的值...
    TextBox tb;
    tb = (TextBox)e.Itme.Cell[0].Controls[0];
    //tb.Text就是你编辑过的值了
      

  3.   

    对于非模板列:
    TextBox tbox=(TextBox)e.Item.Cells[2].Controls[0];
    string ss=tbox.Text;
    对于模板列需要用到FindControl("控件id")
      

  4.   

    private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
     {    
         Lable1.Text=((TextBox)e.Item.Cells[0].Controls[0]).Text;
         Lable2.Text=((TextBox)e.Item.Cells[1].Controls[0]).Text;
         .
         .
         .
     }
      

  5.   

    我是这写的为什么看到的是空值
    Dim bt as Textbox
    Dim ls_code as String
    bt= e.Item.Cells(1).Controls(e.Item.ItemIndex)
    ls_code = bt.Text
    Response.Write(ls_code)
      

  6.   

    bt.Text= e.Item.Cells(1).Controls(0)
    試試..
      

  7.   

    private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    int i=e.Item.ItemIndex;
    SqlData aSqlData = new SqlData();CONNECTION
    aSqlData.Source.Close();
    aSqlData.Source.Open();
    int ff=Int32.Parse(aslw1.Rows[0]["cartoncount"].ToString());---->ASLW1--->DATATABLE
    int g=Int32.Parse((aslwdgq.Rows[i]["totalcbm"].ToString()));
    string t="null";
    string mm="";
    if(aslwdgq.Rows[i]["monthcontainerid"].ToString()=="" || aslwdgq.Rows[i]["monthcontainerid"].ToString()==null)
    {
    mm="null";

    }
    .......
      

  8.   


    Dim bt As TextBox = CType(e.Item.Cells(1).Controls(0),TextBox)
    Dim ls_code as String = bt.Text
    Response.Write(ls_code)
      

  9.   

    (TextBox)e.Item.Cells[0].Controls[0].Text
      

  10.   

    以下是我以前做的在DataGrid中更新的具休代碼﹕用的是c#寫的﹐原理是一樣的。應可以解決你的問題﹕
    //更新按鈕事件處理。
    TextBox name=(TextBox)e.Item.Cells[2].Controls[0];
    TextBox data=(TextBox)e.Item.Cells[3].Controls[0];
    TextBox talk=(TextBox)e.Item.Cells[4].Controls[0];         
              
    SqlConnection conn=new SqlConnection("user id=zjl;password=sa;database=mydb");
      string sql="select * from test";
    SqlDataAdapter ada = new SqlDataAdapter(sql,conn);
    DataSet ds=new DataSet();  
    ada.Fill(ds,"test");
    DataGrid1.DataSource=ds.Tables["test"].DefaultView;
    DataGrid1.DataBind(); DataRow dr=ds.Tables["test"].Rows[(int)e.Item.ItemIndex];
    dr["name"]=name.Text;
    dr["data"]=data.Text ;
    dr["talk"]=talk.Text;
      //在這里如做下這是在頁面上修改了﹐存到頁面上了。 
    //               DataGrid1.EditItemIndex = -1;
      // DataGrid1.DataBind();
         
    Response.Write(e.Item.ItemIndex.ToString()+"<br>");
    Response.Write(name.Text.ToString()+"<br>");
    Response.Write(data.Text.ToString()+"<br>");
    Response.Write(talk.Text.ToString()+"<br>");
      //以上為更新到源數據庫中﹕
    SqlCommandBuilder bd= new SqlCommandBuilder();
              ada.UpdateCommand=bd.GetUpdateCommand();
    ada.InsertCommand=bd.GetInsertCommand();
    ada.DeleteCommand=bd.GetDeleteCommand();
    ada.Update(ds,"test"); ada.Update(ds,"test"); conn.Open();
    ada=new SqlDataAdapter(sql,conn);
    ada.Fill(ds,"test");
    conn.Close();
    DataGrid1.EditItemIndex = -1;
    DataGrid1.DataBind();
           
    }