HighTechTalks DotNet Forums  

Getting the data bound to a Repeater

ASP.net Web Controls microsoft.public.dotnet.framework.aspnet.webcontrols


Discuss Getting the data bound to a Repeater in the ASP.net Web Controls forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Nathan Sokalski
 
Posts: n/a

Default Getting the data bound to a Repeater - 12-06-2007 , 02:19 PM






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
  #2  
Old   
Peter Bromberg [C# MVP]
 
Posts: n/a

Default RE: Getting the data bound to a Repeater - 12-06-2007 , 02:44 PM






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:

Quote:
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
  #3  
Old   
Milosz Skalecki [MCAD]
 
Posts: n/a

Default RE: Getting the data bound to a Repeater - 12-06-2007 , 02:45 PM



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:

Quote:
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 Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.