Best Technique for Multiple Eval Fields in Gridview ItemTemplate?

拜拜、爱过 提交于 2019-11-30 11:26:20

问题


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.


回答1:


Even clearer, IMO, is:

<%# String.Format("{0} - {1}", Eval("Name1"), Eval("Name2")) %>



回答2:


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'




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/55607/best-technique-for-multiple-eval-fields-in-gridview-itemtemplate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!