Getting the data bound to a Repeater

  • Thread starter Nathan Sokalski
  • Start date
N

Nathan Sokalski

I am attempting to get the data that was bound to an item in a Repeater
control for use in the ItemDataBound event. Here is the code I am using to
attempt to retrieve the data:

CType(e.Item.DataItem, DataRowView)("fieldname")

This has normally worked for me in the past, but once in a while it gives me
a problem for reasons I cannot understand. The error I am recieving is:

Object reference not set to an instance of an object.

I know that the datatable that I am binding to the Repeater has data in it,
because the data is displayed on the page if I comment out this line of the
code. Does anybody have any idea what I am doing wrong? Thanks.
 
P

Peter Bromberg [C# MVP]

It might not be the correct item type because of header templates etc., e.g.
(C#):

if( e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
// FindControl code here
}
 
M

Milosz Skalecki [MCAD]

Hi Nathan,


Before you access assiociated DataItem check the current item's type:
If e.Item.ItemType = ListItemType.Item or _
e.Item.ItemType = ListItemType.Item then

CType(e.Item.DataItem, DataRowView)("fieldname")

end if

hope it helps
 

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
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top