?
Solved

Grabbing a value for current row in ItemDataBound of Repeater

Posted on 2008-11-04
8
Medium Priority
?
2,484 Views
Last Modified: 2012-05-05
I get a null exception when trying to access a value for the current boundrow in my repeater.  I'm probably just  missing something here?

 

    public void rptSearchStrings_DataBound(Object sender, RepeaterItemEventArgs e)
    {
 

    public void rptPartStrings_DataBound(Object sender, RepeaterItemEventArgs e)
    {
        DataRowView dv = e.Item.DataItem as DataRowView;
        string partString = ((DataRowView)e.Item.DataItem).Row["partstring"].ToString();

....

 dv is null

....

 dv is null
0
Comment
Question by:dba123
  • 4
  • 2
7 Comments
 
LVL 26

Accepted Solution

by:
Anurag Thakur earned 1500 total points
ID: 22877803
try to cast it as a datarow
the sample from msdn is for a object data source but you are nearly there - you dv is null because i think its a row and not a view
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.itemdatabound.aspx
0
 
LVL 1

Author Comment

by:dba123
ID: 22877929
I'm still not finding the right way to access the current row and a specific value in the row's columns.
0
 
LVL 13

Expert Comment

by:sm394
ID: 22877956
try that
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{

DataRowView dv = e.Item.DataItem as DataRowView;
string partString = ((DataRowView)e.Item.DataItem).Row["partstring"].ToString();

}
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:dba123
ID: 22878162
sm394, I don't see how yours is different from what I just posted originally.
0
 
LVL 1

Author Comment

by:dba123
ID: 22878166
I put that check in for item or alternating item, and it makes no difference
0
 
LVL 1

Author Comment

by:dba123
ID: 22879181
figured it out.  You can just case the e.Data.Item to the orignal object type and use that type directly

(Product)e.Item.DataItem

then

Product.PropertyName (or column name really)
0
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 22879995
thats what my link suggested if you might have had a look deeply
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Screencast - Getting to Know the Pipeline
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question