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:
01310866
Views:
8
This message has been marked as the solution to the initial question of the thread.
>>>Hi everybody,
>>>
>>>How can I access fields my GridView is bound to in its RowBound method?
>>>
>>
>>Look at the e.Row.DataItem object.
>
>The only way I can found is to use
>string PersonName = e.Row.Cells[5].Text + " " + e.Row.Cells[6].Text; which I don't like since how would I know that 5th column is the First Name and 6th is the Last Name?
>

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.
-Paul

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

Click here to load this message in the networking platform