Link to home
Start Free TrialLog in
Avatar of dba123
dba123

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of Anurag Thakur
Anurag Thakur
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dba123
dba123

ASKER

I'm still not finding the right way to access the current row and a specific value in the row's columns.
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();

}
Avatar of dba123

ASKER

sm394, I don't see how yours is different from what I just posted originally.
Avatar of dba123

ASKER

I put that check in for item or alternating item, and it makes no difference
Avatar of dba123

ASKER

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)
thats what my link suggested if you might have had a look deeply