如何用DataGrid实现多行数据的同时更新呀?我现在正在写一个程序,需要同时更新多行记录的值 ,我应该如何实现呀!希望高手能过来帮帮小妹!谢了!

解决方案 »

  1.   

    不太清楚,DataGrid的datasource 是什么?
      

  2.   

    更新数据集DataSet,重新绑定!
    this.DataGrid.DataSource = DataSet.Tables[0].DefaultView;
    this.DataGrid.DataBind();
      

  3.   

    在DataGrid中加入DataGrid_ItemCommand事件!
      

  4.   

    然后在加入以下代码即可!
    public void MyDataGrid_ItemCommand(object source,System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    string err;
       
    if (e.CommandName == "Add")
     {
    foreach (DataGridItem di in MyDataGrid.Items)
    {
    if (di.ItemType==ListItemType.Item || di.ItemType == ListItemType.AlternatingItem )
    {
    string sQTY;
    double dQTY;
    string sCategory=this.dlstCategory.SelectedItem.Text.Trim ();
    sQTY=((TextBox)e.Item.FindControl("edit_st_QTY")).Text;
    sQTY =((TextBox)di.FindControl("txtQTY")).Text.Trim();

    if (sQTY =="")
    sQTY = "0";
    try
    {
    dQTY=Convert.ToDouble(sQTY);
    }
    catch 
    {
    err = "数量类型错误 !";
    goto error;
    }
         if (dQTY > 0 ) 
    {
    Account myAccount = Account.MyAccount;
    Stock acct = new Stock (nIntCode,dQTY,sStatus,myAccount.userId);
    err = acct.AddNew(); 
    if (err != "")
    goto error;
    }
    }