private void Dg_huiyuan_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{   
int User_ID = Convert.ToInt32(e.Item.Cells[0].Text);
string User_Prio = ((TextBox)e.Item.Cells[7].Controls[0]).Text;
string sqlstr = "update [user] set User_Prio='"+User_Prio+"' where User_ID="+User_ID;
SqlCommand comm = new SqlCommand(sqlstr,conn);
conn.Open();
comm.ExecuteNonQuery();
conn.Close();
Dg_huiyuan.EditItemIndex = -1;
BinGrid();
}我在上面的代码中为什么获得的User_Prio是原来绑定时候的数据而不是我在编辑后的数据啊

解决方案 »

  1.   

    e.Item.Cells[0].Text);
    你这样能取到你编辑框的值
      

  2.   

    要加入这个:
    for (int i=0;i<dgrida1.Item.count;i++)
    {
       int User_ID = Convert.ToInt32(dgrid1.Item[i].Cell[0].Text);
    }
      

  3.   

    你的DATAGRID中有没有这个属性呢?DataKeyField="User_ID"设置这个属性后在程序中用这种方法取值:User_ID = myDataGrid.DataKeys[(int)e.Item.ItemIndex];
      

  4.   

    顶啊我的页面上是这样写的
    <asp:BoundColumn Visible="False" DataField="User_ID" HeaderText="User_ID" ReadOnly="True"></asp:BoundColumn>
      

  5.   

    DATAGRID中象你这样写,好象取不出来吧
      

  6.   

    TableCell cellValue;
          DataRow updata_row =Table_Bill.Rows.Find(DG_Context.DataKeys[e.Item.ItemIndex] );
          cellValue = e.Item.Cells[2];
      

  7.   

    在page_load里
    If(!IsPostBack){
    ...
    }
      

  8.   

    我要获得的是编辑后的textbox中的直啊<asp:BoundColumn DataField="User_Prio" HeaderText="权限"></asp:BoundColumn>