[再一次_求助]DataGrid 更新时取得绑定列的问题。附代码。问题是取不到值。谢谢。难道问题很大吗。
这是更新代码:
protected void DataGrid_Upadte(object source, DataGridCommandEventArgs e)
{
try
{
con.Open();
string sqlUpdate = "update Power set PowerName=@PowerName,PowerLink=@PowerLink where PowerID=@PowerID ";
SqlCommand com = new SqlCommand(sqlUpdate, con);
com.Parameters.Add(new SqlParameter( "@PowerName ", SqlDbType.VarChar, 50));
com.Parameters.Add(new SqlParameter( "@PowerLink ", SqlDbType.VarChar, 100));
com.Parameters.Add(new SqlParameter( "@PowerID ",SqlDbType.Int));
com.Parameters[ "@PowerName "].Value =((TextBox)(e.Item.Cells[2].Controls[0])).Text;//注:要是把“SSS”等字符串赋予它就可以写入
com.Parameters[ "@PowerLink "].Value =((TextBox)(e.Item.Cells[3].Controls[0])).Text;//注:要是把“SSS”等字符串赋予它就可以写入 com.Parameters[ "@PowerID "].Value = Dg_Edit.DataKeys[(int)e.Item.ItemIndex];
com.ExecuteNonQuery();
string s = com.CommandText;
Dg_Edit.EditItemIndex = -1;
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
finally
{
if (con.State != ConnectionState.Closed)
con.Close();
}
dataBindToDataGrid();
}
下面是datagrid的代码:
<asp:DataGrid ID= "Dg_Edit " runat= "server " AutoGenerateColumns= "False " DataKeyField= "PowerID "