Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
DataBound GridView - accessing fields in RowBound method
Message
General information
Forum:
ASP.NET
Category:
Other
Environment versions
OS:
Windows XP
Database:
MS SQL Server
Miscellaneous
Thread ID:
01310810
Message ID:
01328549
Views:
8
This message has been marked as a message which has helped to the initial question of the thread.
>>If it's bound to something like a datatable, code like this should work:
>>
>>
>>if (e.Row.DataItem is DataRowView)
>>{
>>   DataRowView view = e.Row.DataItem as DataRowView;
>>   string field = view["FieldInTable"].ToString();
>>}
>>
>>
>>Basically you cast DataItem to the correct underlying type, then reference the elements the standard way for that type.
>
>In my case it's bound to an object. Somehow this code doesn't work for me. I can go back with Cells approach, but I really like this syntax better.

Cast it to the object type, then reference it's properties directly, ex. instead of DataRowView view = e.Row.DataItem as DataRowView, change "DataRowView" to the true object type. Then use view.PropertyName to access it.
-Paul

RCS Solutions, Inc.
Blog
Twitter
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform