I have a gridview with columns one of which is an ID that is the Key for a table.
I use that Key to allow users to Delete that record from the DB. The user clicks a checkbox on the row they wish to Delete then clicks a button at which point I loop through all the rows of the gridview and if the current row has the checkbox checked I get the ID then Delete the record from the database.
Sometimes the code doesn't 'see' the ID. That column is hidden but that shouldn't make a difference.
This is how I access the data in the cell:
string iID = gvData.Rows[i].Cells[MyGlobalFuncWebCtrls.GetColumnIndexByName(row, "ID")].Text;
Sometimes the iID value is a blank string. Perplexing.
I have an Image in a different cell that uses that ID to get the record and populate another screen to Edit the record and it never fails:
<asp:LinkButton id="btn_Edit" runat="server" CommandName="Edit_Record"
CommandArgument='<%#string.Format("{0}", Eval("ID"))%>'>
<asp:Image id="imgEdit" runat="server" ImageUrl="images/edit.gif" style="border: 0;" />
</asp:LinkButton>
Any ideas on why looping through the gridview rows sometimes comes up empty?
Thanks.