设计前台页面:
<Columns>
<asp:BoundField DataField="id" HeaderText="ID" />
<asp:BoundField DataField="wo" HeaderText="Production Order" />
<asp:TemplateField HeaderText="confirm">
<ItemTemplate>
<asp:TextBox ID="TextBox_confirm" runat="server" Text =<%# DataBinder.Eval(Container.DataItem,"onhand_confirm") %>></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
后台程序:
Page_Load里面必须要加上这句判断,其实任何一个有数据绑定的页面都需要加这一句:
if (!Page.IsPostBack)
{
databind();
}
在update数据的按钮事件上增加下面动作:
string connectionstrings = "server=sham1336;UID=sa;PWD=******;DataBase=supermarket";
SqlConnection connection = new SqlConnection(connectionstrings);
connection.Open();
//提交config数据
int i = 0;
while (i < GridView1.Rows.Count)
{
TextBox confirmbox = (TextBox)GridView1.Rows[i].FindControl("TextBox_confirm");
double confirmnum = 0;
if (confirmbox.Text.ToString().Trim() == "")
{
confirmnum = 0;
}
else
{
confirmnum = Convert.ToDouble(confirmbox.Text.ToString());
}
int configid = Convert.ToInt32(GridView1.Rows[i].Cells[0].Text.ToString());
string pullwipstring = "update pullwip set onhand_confirm = " + confirmnum +" where id = " + pullwipid;
SqlCommand pullwipcommd = new SqlCommand(pullwipstring, connection);
pullwipcommd.ExecuteNonQuery();
i++;
}