I have 2 datagrids. Both with checkboxes. I have a nested foreach loop that gets the DataKeys values of both checked persons from both datagrids. When I run the debugger the first datakey gets assigned to the correct variable oIdividualID. That is working fine. The second foreach loop gets the datakey from the next datagrid. That works fine too. However, it is not assigning it to the variable oNewParentID. and At the bottom of my code, in debugging, the method I am calling holds the value of oIndividualID correctly, But oNewParentID Holds NO value? Is there something wrong with my nested foreach loop? I don’t understand. Here’s my code:
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));
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));
Individual ind = new Individual();
ind.ReassignIndividual(oIndividualID, oNewParentID);
}
}
gvReassignCustomers.DataBind();
gvAdminCustomer.DataBind();
}
}
}
hard to understand the purpose of the code – for every checked tickbox in Admin grid you’re running reassign on every checked Reassign grid. Is it really the intent?
And then you’re running DataBind() for every line on in admin grid.
So.
Comment out DataBind() – you don’t need them there, it’s just tells the system to rebind the data to the grids which can potentially clear the user ticked tickboxes.