/ Published in: C#

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//The simplest way is: <%# Eval("DivID") %> //This calls DataBinder.Eval behind the scenes. //For ultimate performance, Use explicit casting instead of DataBinder.Eval to avoid reflection: Replace: <td><%# DataBinder.Eval(Container.DataItem, "field1") %></td> with <td><%# ((DataRowView)Container.DataItem)["field1"] %></td> //or, if using EF/LINQ, cast to the underlying datatype: <%# ((ftj.com.App_Data.ProductFAQ)Container.DataItem).Question %> //you even get intellisense support. NOTE: For above to work, must add <%@ Import Namespace="System.Data" %> to web form. Alternatively, call via fully qualified System.Data.DataRowView. //however, this assumes the scope of the current databind. With longer syntaxes below you can hit items in other scopes or drill deeper into current scope. <p><strong>Member Conditions</strong></p> <asp:Repeater runat="server" ID="rptMemberCondition"> <ItemTemplate><asp:HyperLink runat="server" Text='<%# DataBinder.GetPropertyValue(Container.DataItem, "ConditionDescription") %>' CausesValidation="false" NavigateUrl='<%# "~/ApplyNow/Step5.aspx?ID=" + DataBinder.GetPropertyValue(Container.DataItem, "ID") %>' /><br /></ItemTemplate> </asp:Repeater> //Alternatively, you can use eval instead of GetPropertyValue. This is useful when the object has a property that contains a nested object. e.g. <%# DataBinder.Eval(Container.DataItem, "ProductType.Name") %>
URL: http://weblogs.asp.net/jgalloway/archive/2005/09/20/425687.aspx
Comments
