Grabbing a value for current row in ItemDataBound of Repeater

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
LVL 1
dba123Asked:
Who is Participating?
 
Anurag ThakurTechnical ManagerCommented:
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
 
dba123Author Commented:
I'm still not finding the right way to access the current row and a specific value in the row's columns.
0
 
sm394Commented:
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
dba123Author Commented:
sm394, I don't see how yours is different from what I just posted originally.
0
 
dba123Author Commented:
I put that check in for item or alternating item, and it makes no difference
0
 
dba123Author Commented:
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
 
Anurag ThakurTechnical ManagerCommented:
thats what my link suggested if you might have had a look deeply
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.