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

Personalization on fly

3 Answers 121 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Julio Cesar
Top achievements
Rank 1
Julio Cesar asked on 04 Apr 2012, 12:25 AM
Hi, I need to personalizate the view for each element to show on the grid.

how can i make it?

I can insert code in the ItemTemplate ?
I need to do something like this:

if (eval(something).ToString() != "")
{
    <span style="font-weight: bold;">Something:</span><%# Eval("something") + "%>
}

I need it, because every row could have some empty column on it and I should not show the information about that column.

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 04 Apr 2012, 11:24 AM
Hi,

Here is the code I tried to show information only for those non empty columns. You can give the condition inside the ItemTemplate using a Ternary Operator.

ASPX:
<telerik:GridTemplateColumn>
 <ItemTemplate>
  <span id="Span1" runat="server" style="font-weight:bold"> <%#(String.IsNullOrEmpty(Eval("ShipName").ToString()) ? " " :"Something: "+Eval("ShipName")  )%></span>
 </ItemTemplate>
</telerik:GridTemplateColumn>

Regards,
Shinu.
0
Julio Cesar
Top achievements
Rank 1
answered on 09 Apr 2012, 07:11 PM
Hi, Thank you for answer...

I have a question related about...

what is the difference between
<%#
and 
<%=
?

because the first expression don't let me use sentences like if or switch and the second one can do it...

Thanks and my apologies if this question should not to be here...
0
Shinu
Top achievements
Rank 2
answered on 10 Apr 2012, 05:23 AM
Hi,

<%# %>  is Data Binding Expression Syntax.All data-binding expressions must be contained between <%# and %> characters.Data-binding expressions use the Eval and Bind methods to bind data to controls and submit changes back to the database.

Example:
<asp:label text='<%# Eval("ShipName") %>' runat="server"/>


<%= %>  is most useful and simplest way to display information from an ASP.NET program.Another approach is to use the Response.Write statement.

Example:
Hello <%= name %>!


Thanks,
Shinu.
Tags
Grid
Asked by
Julio Cesar
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Julio Cesar
Top achievements
Rank 1
Share this question
or