Reputation: 2560
I want to insert an image to a LinkButton programmatically like the following aspx code:
<asp:LinkButton runat="server" ><img src="NewImages/tick.jpg" runat= "server" /></asp:Linkbutton>
I am trying the following code:
LinkButton bb = (System.Web.UI.WebControls.LinkButton)pagerTable.Rows[0].Cells[0].Controls[0];
bb.Attributes.Add("img", "NewImages/tick.jpg");
P.S PLease do not tell me to use an ImageButton :). There is a reason using this
Upvotes: 0
Views: 8025
Reputation: 6572
you can use like this
<asp:LinkButton ID="LinkButton1" runat="server" />
LinkButton1.Text = "<img src='NewImages/tick.jpg'/>";
Upvotes: 0
Reputation: 50114
You need to do something along the lines of
bb.Controls.Add(new Image { ImageUrl = "NewImages/tick.jpg" });
i.e. create an Image
control and add it to the LinkButton
's child controls.
Upvotes: 4
Reputation: 1082
you can try this:
LinkButton bb = (System.Web.UI.WebControls.LinkButton)pagerTable.Rows[0].Cells[0].Controls[0];
HtmlImage i = bb.Controls[0] as HtmlImage;
i.Src = "~/NewImages/tick.jpg";
Upvotes: 0