Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Getting the data bound to a Repeater

Reply
Thread Tools

Getting the data bound to a Repeater

 
 
Nathan Sokalski
Guest
Posts: n/a
 
      12-06-2007
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.

 
Reply With Quote
 
 
 
 
Peter Bromberg [C# MVP]
Guest
Posts: n/a
 
      12-06-2007
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
}
--
Site: www.eggheadcafe.com
UnBlog: petesbloggerama.blogspot.com
Metafinder: www.blogmetafinder.com



"Nathan Sokalski" wrote:

> 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.
>
>

 
Reply With Quote
 
 
 
 
Milosz Skalecki [MCAD]
Guest
Posts: n/a
 
      12-06-2007
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
--
Milosz


"Nathan Sokalski" wrote:

> 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.
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting the data bound to a Repeater Nathan Sokalski ASP .Net 2 12-06-2007 08:45 PM
Can I use the value of a bound data item within repeater, without binding it? mark4asp ASP .Net 1 12-03-2007 06:51 PM
Getting the Value of a field bound to a Repeater John Kotuby ASP .Net 3 04-19-2007 06:18 PM
How to represent the data in a not bound control via bound control Mario Krsnic ASP .Net 0 06-23-2006 07:38 AM
Getting lower-bound and upper-bound of strings input Rhiner Dan C++ 1 03-27-2005 02:03 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57