Return to Snippet

Revision: 32319
at January 27, 2011 04:20 by housecor


Updated Code
//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") %>

Revision: 32318
at January 27, 2011 03:26 by housecor


Updated Code
//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>

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") %>

Revision: 32317
at January 27, 2011 03:26 by housecor


Updated Code
//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>

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") %>

Revision: 32316
at January 27, 2011 03:11 by housecor


Updated Code
The simplest way is: <%# Eval("DivID") %>

//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") %>

Revision: 32315
at October 20, 2010 01:46 by housecor


Updated Code
<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") %>

Revision: 32314
at September 22, 2010 11:11 by housecor


Updated Code
<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>

Revision: 32313
at September 22, 2010 11:01 by housecor


Initial Code
<%# DataBinder.Eval(Container.DataItem, "Name") %>

Initial URL
http://weblogs.asp.net/jgalloway/archive/2005/09/20/425687.aspx

Initial Description


Initial Title
Reference databound value in webform

Initial Tags


Initial Language
C#