So I have a method I wrote that will copy the selectedValue from one dropdownbox to another in a specific row. It is called from a button on the row on the OnCommand Event.
protected void Copy(String From, String To, GridViewRow CurrentRow)
{
DropDownList FromList = (DropDownList)CurrentRow.FindControl(From);
DropDownList ToList = (DropDownList)CurrentRow.FindControl(To);
ToList.SelectedValue = FromList.SelectedValue;
}
Now When I use this on a footer row everything works fine, however, when I try to call this while editing a row, I can see data if I Debug, however, the dropdown will not populate. No errors, occur.
I did step Into thru the process, and it’s calling my Grids RowEditing event (Which populates all the dropdowns) again after my OnCommand Event fires. So my guess is that its just wiping out the changes I made by repopulating the dropdowns.
Is there a way to prevent the RowEditing event from refiring (even if its just so I can prove myself right or wrong)? Should I be handling this copy in some other way?
So I found my issue this morning, and it was because I was using the CommandName attribute on my button, or more specifically the name I was using.
I thought the CommandName was just an empty spot for you to pass a value, but if you use a certain name, like “Edit”, it will actually kick off the RowEditing event for the grid the button is associated with.
I didn’t think this would work this way (considering is was associated with the button, not the Grid) but as soon as I changed the command name, it worked just fine. I changed it back, and it was broken again.