开发者

Listview Pagination - Index Out of range error?

开发者 https://www.devze.com 2023-04-09 23:26 出处:网络
I am having trouble implementing pagination onto a list of products held within a List View. Currently my pagination set up works fine if I do not call the ItemDataBound method but once I do, I repeat

I am having trouble implementing pagination onto a list of products held within a List View. Currently my pagination set up works fine if I do not call the ItemDataBound method but once I do, I repeatedly get the error that an Index was out of range when I tr开发者_开发知识库y to navigate using my pagination.

This line seems to be causing the error, even though debug seems to show that it is finding the ID

int key = int.Parse(LV_Images.DataKeys[e.Item.DataItemIndex].Value.ToString());

Does anyone have a workaround this or can explain why this is happening??? Many thanks!


Use the following:

int key = int.Parse(LV_Images.DataKeys[e.Item.DisplayIndex].Value.ToString());

I was having same error also, I was able to resolve it with this. Hope this helps someone else


The only container you are using in this line is DataKeys. The possible cause of this is because e.Item.DataItemIndex is not in range. Can you please check what is the value of DataItemIndex when it throws this exception? Also, check whether the value exist for such index value.

0

精彩评论

暂无评论...
验证码 换一张
取 消