开发者

Set asp:LinkButton text in markup

开发者 https://www.devze.com 2023-01-12 17:22 出处:网络
How would it be possible to set text of ASP.NET LinkButton l开发者_Python百科ike below: <asp:LinkButton id=\"LinkButton_Select\" runat=\"server\" Text=\'

How would it be possible to set text of ASP.NET LinkButton l开发者_Python百科ike below:

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


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>"%>'/>


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>


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")) %>'/> 


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.


I found this answer which is the most simple:

Text='<%# "

"+ Eval("Start") + "

" + Eval("End")+"

"

Thanks all!


This worked for me, set the value of attribute text in the page load.

Example:

yourpage.aspx

<asp:Button ID="yourButtonId" runat="server" OnClick="StartEvent" />

yourpage.aspx.cs

protected void Page_Load(Object sender, EventArgs e)
{
    // Set Text asp:Button
    yourButtonId.Text = "Your text";
}
0

精彩评论

暂无评论...
验证码 换一张
取 消