ASP.net GridView Shortcut
When dealing with Strongly Typed datasets on the ASP.net GridView 2.0, I found myself writing one too many lines of code like this:
<asp:TemplateField HeaderText="Category">
<ItemTemplate>
<%# DataBinder.Eval(
((System.Data.DataRowView) Container.DataItem).Row,
"CategoryRow.CategoryName") %>
</ItemTemplate>
<asp:TemplateField>
Solution?
<asp:TemplateField HeaderText="Category">
<ItemTemplate>
<%# EvalEx(Container.DataItem, "CategoryRow.CategoryName") %>
</ItemTemplate>
<asp:TemplateField>
protected object EvalEx(object DataItem, string Expression)
{
return DataBinder.Eval(((DataRowView) DataItem).Row, Expression);
}
About this entry
You’re currently reading “ ASP.net GridView Shortcut ,” an entry on Chui's Counterpoint
- Published:
- 6.5.06 / 9pm
- Category:
- .Net
3 Comments
Jump to comment form | comments rss [?] | trackback uri [?]