|
楼主发表于:2009-01-10 08:53:32
代码如下: - C# code
asp:TextBox id="tb1" runat="server" Width="80px" Text='<%# DataBinder.Eval(Container, "DataItem.g_sm") %>'></asp:TextBox>
<asp:LinkButton ID="bt1" runat="server" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "g_id")%>' CommandName="mn">修改</asp:LinkButton>
=================================== - C# code
private void DataGrid1_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if (e.CommandName == "mn")
{
TextBox title1=(TextBox)DataGrid1.Items[0].FindControl("tb1");
string aaa=title1.Text;
SqlConnection MyConnection = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["connectionString"]);
string strUpdate = "Update gwc set g_sm=@a1 Where g_id='"+e.CommandArgument.ToString()+"'";
SqlCommand cmdUpdate = new SqlCommand( strUpdate, MyConnection );
cmdUpdate.Parameters.Add( "@a1",aaa);
MyConnection.Open();
int intUpdateCount = cmdUpdate.ExecuteNonQuery();
MyConnection.Close();
//
BindGrid1();
}
}
=============================== 以上的代码运行结果是: string aaa=title1.Text; 这个值老是和第一行的值,即修改第一行的TextBox的值,是可以修改的,但修改第二行、第三行的值,等等,都是默认改成了第一行的值; 意思是:TextBox的值不能按行来修改。 我对Datagrid不太懂,希望高手能指点一二。 |
|
|
|