This is a migrated thread and some comments may be shown as answers.

Usage Eval / Datafield in Grid ItemTemplate

3 Answers 781 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dave Crack
Top achievements
Rank 1
Dave Crack asked on 28 Apr 2010, 11:09 AM
Hi,
i've searching a while in the Forum but i couldn't find how to use Eval within a ItemTemplate.

Whats working:
<telerik:GridTemplateColumn UniqueName="infos" DataField="id" HeaderText="Infos"
<ItemTemplate> 
Brand: <%#Eval("brandId")%> 
<%=BrandDDL.Items[0].Text%> 
</ItemTemplate> 
</telerik:GridTemplateColumn> 

But when I try to use the ID from Eval to get the corresponding Text like this

<telerik:GridTemplateColumn UniqueName="infos" DataField="id" HeaderText="Infos"
<ItemTemplate> 
Brand: <%#Eval("brandId")%>       
<%=BrandDDL.Items[(int)Eval("brandId")].Text%> 
</ItemTemplate> 
</telerik:GridTemplateColumn> 

I get a InvalidOperationException Context Runtime Error Eval(), XPath() and Bind().
Is there any way to get the ID from the DataField of the current Row within ItemTemplate to work
with it in <% %> and also make some if(!string.IsNullOrEmpty(id)){}...

Thanks.






3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 29 Apr 2010, 06:57 AM
Hi,

You could try the following code and check whether it helps you.

  
 <telerik:GridTemplateColumn UniqueName="infos" DataField="id" HeaderText="Infos">  
         <ItemTemplate> 
              Brand: 
              <%#Eval("ID") %> 
               <%#BrandDDL.Items[Convert.ToInt32(Eval("ID"))].Text%> 
          </ItemTemplate>  
 </telerik:GridTemplateColumn>  


Regards,
Princy.
0
Dave Crack
Top achievements
Rank 1
answered on 04 May 2010, 02:29 PM
Nope. Have you tried it? I get only:
Data binding methods such as Eval (), XPath () and Bind () can be used only in the context of a data-bound control.

Is there maybe any example where <%#Eval("xyz")%> was used within <ItemTemplate>

This ist also not working
<%
if(Eval("xyz") != null)
{
}
%>

Same Exception:

System.Web.UI.Page.GetDataItem()
System.Web.UI.TemplateControl.Eval(String expression)
ASP.Test_aspx.__Render__control22(HtmlTextWriter __w, Control parameterContainer) in d:\net3.5\Test.aspx:Zeile 269.
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
0
Tsvetoslav
Telerik team
answered on 10 May 2010, 08:44 AM
Hi Dave,

Did you change your expression evaluation tags from <%=................%> to <%#......................%> as Princy has indicated? Attached is a sample that demonstrates that the binding expressions work all right within the ItemTemplate of a GridTemplateColumn.

Hope it helps.

Regards,
Tsvetoslav
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
Dave Crack
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Dave Crack
Top achievements
Rank 1
Tsvetoslav
Telerik team
Share this question
or