Problem with GridView

  • Thread starter Thread starter Bruno Piovan
  • Start date Start date
B

Bruno Piovan

Hello,
I'm having a strange problem with gridview, I have a portion of code that
binds data to the gridview:

gvCategories.DataSource = dt
gvCategories.DataKeyNames = New String() {"id_category"}
gvCategories.DataBind()

and I have a RowDeleting event handler that does the following:

#1 Dim id_category As Integer =
CInt(gvCategories.DataKeys(e.RowIndex).Value)
#2 CType(Session("GamesXCategories"),
GamesDS.GamesXCategoriesDataTable).FindByid_gameid_category(id_game,
id_category).Delete()

it was working very good before, but now I get an error in the line #1, the
error is "Index was out of range. Must be non-negative and less than the
size of the collection."

I don't understand what is happening...... it was working before, I put a
breakpoint on line #1 and I check, there is rows in the grid view....

thanks in advance!

Bruno
 
DataKeyNames is a string where multiple key fields would be separated by
commas. It should be

gvCategories.DataKeyNames = "id_category"
 
Back
Top