Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best Technique for Multiple Eval Fields in Gridview ItemTemplate?

What is the best way to use multiple EVAL fields in a GridView ItemTemplate?

Looking to have some control over formatting for appearance as well as setting up hyperlinks/javascript etc.

like image 205
Dhaust Avatar asked Sep 11 '08 01:09

Dhaust


4 Answers

Even clearer, IMO, is:

<%# String.Format("{0} - {1}", Eval("Name1"), Eval("Name2")) %> 
like image 136
Forgotten Semicolon Avatar answered Oct 05 '22 14:10

Forgotten Semicolon


I had previously used this (bad, I know):

<%# Eval("Name1", "{0} - ")%> <%#Eval("Name2")%> 

Result = 'John - Smith'

But just discovered that I can also put TWO (or more) Evals in the same data-bound group:

<%#Eval("Name1") & " - " & Eval("Name2")%> 

Result = 'John - Smith'

Or

<%# "First Name - " & Eval("Name1") & ", Last Name - " & Eval("Name2")%>   

Result = 'First Name - John, Last Name - Smith'

like image 44
Dhaust Avatar answered Oct 05 '22 14:10

Dhaust


Eval and Bind both suck.
Why get the property through reflection? You can access it directly like this:

((MyObject)Container.DataItem).MyProperty

It's not like the object is unknown to you at runtime. That's my two cents, anyhow.

like image 27
Esteban Araya Avatar answered Oct 05 '22 13:10

Esteban Araya


I have a easiest way to do this same thing...

<asp:Label ID="lblName" runat="server" Text='<%#Eval("FirstName").ToString() +", "+ Eval("LastName").ToString() %>'></asp:Label>

.

<%#Eval("FirstName").ToString() +", "+ Eval("LastName").ToString() %>

Here both objects are converted into string the concatenate them.

like image 21
Durgesh Pandey Avatar answered Oct 05 '22 13:10

Durgesh Pandey