2012-02-29 98 views
0

我正在循環2個Datagrids並獲取所選人員的IndividualID(PrimaryKeys)。我已經調試過了,循環工作正常。無論如何,當我從我的表適配器調用我的更新方法時,似乎沒有任何事情發生。它不更新。這是我的代碼。不知道我在做什麼錯:嘗試調用按鈕單擊事件中的更新方法

protected void imgbtnReassgin_Click(object sender, ImageClickEventArgs e) 
{ 




    foreach (GridViewRow row in gvAdminCustomer.Rows) 
    { 
     CheckBox cb = (CheckBox)row.FindControl("chkitemSelectorCustomers"); 
     if (cb != null && cb.Checked) 
     { 


      int oIndividualID = Convert.ToInt32((gvAdminCustomer.DataKeys[row.RowIndex].Value)); 
      // GlobalVar.oIndividualID = oIndividualID; 


      foreach (GridViewRow r in gvReassignCustomers.Rows) 
      { 
       CheckBox chkBox = (CheckBox)row.FindControl("chkitemSelectorAllManagersandSalesman"); 
       if (chkBox != null && chkBox.Checked) 
       { 

        int oNewParentID = Convert.ToInt32((gvReassignCustomers.DataKeys[r.RowIndex].Value)); 


        individualTableAdapter ind = new individualTableAdapter(); 

        //Individual ind = new Individual(); 
        ind.reassign_Individual(oIndividualID, oNewParentID); 

       } 

      } 
      gvAdminCustomer.DataBind(); 


     } 


    } 

} 

回答

1

它是更新數據庫記錄,並沒有反映在網格上?如果是這種情況,那麼它看起來就是在循環之前用它使用的數據源重新綁定網格。你需要刷新你的數據集,然後重新綁定:

gvAdminCustomer.DataSource = YourDataSource;  
gvAdminCustomer.DataBind(); 

祝你好運!

+0

它根本沒有更新數據庫。但我會嘗試這種方法。 – 2012-03-01 17:33:11