Problem with GridView

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
 
C

Christopher Reed

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

gvCategories.DataKeyNames = "id_category"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top