views:

31

answers:

5

Hi,

How would it be possible to set text of ASP.NET LinkButton like below:

<asp:LinkButton id="LinkButton_Select" runat="server" Text='
<p><%# DataBinder.Eval(Container.DataItem, "Start")%></p>&nbsp;
<p><%# DataBinder.Eval(Container.DataItem, "End")%></p>
'/>

Thanks in advance.

A: 

try something like

<asp:LinkButton id="LinkButton_Select" runat="server" Text='<%# string.Format("<p>{0}</p>&nbsp;<p>{1}</p>",DataBinder.Eval(Container.DataItem, "Start"),DataBinder.Eval(Container.DataItem, "End")) %>'/> 
asawyer
Thanks. The above answer is simpler!
JoesyXHN
+1  A: 

Why not just do the below:

<p><asp:LinkButton id="LinkButton_Select" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Start")%>'/><p>
<p><asp:LinkButton id="LinkButton_Select2" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "End")%>'/><p>
Ben Robinson
This is also good as well. but I prefer to use only one linkButton.
JoesyXHN
+2  A: 

Try this

<asp:LinkButton id="LinkButton_Select" runat="server" Text='<%# "<p>"+ DataBinder.Eval(Container.DataItem, "Start")+"</p>&nbsp;<p>"+DataBinder.Eval(Container.DataItem, "End")+"</p>"%>'/>
StrouMfios
Thanks! It works!
JoesyXHN
But a <p> tag inside an <a> tag is still invalid HTML.
Stuart
A: 

Your code will fail because, on a runat="server tag, each attribute has to either be completely a '<%# %>' section, or not at all. You can't use <%# %> for part of it and plain text for the rest. @StrouMfios showed the way around that using string.Format, but there's another issue - when converted to HTML, you'd end up with an <a> tag containing <p> tags, which is illegal. If splitting it up into two separate linkbuttons doesn't work for you, the only other way you could do it legally is by using <span> tags styled to be display:block with extra spacing.

Stuart
A: 
JoesyXHN