how to change src from code behin of data list image control

Posted by Sudhir under Regular Expressions on 11/3/2009 | Views : 4789 | Status : [Member] | Replies : 7
<asp:datalist id="dllimage" runat="server">
<img id="star" runat="server" src="images/star.gif">
</asp:datalist>
I want to change src of above image from code behind file.
how can it is possible. any one give me idea for that.




Responses

Posted by: Vuyiswamb on: 11/4/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Good Morning Sudhir

Firstly your code is not correct. the Tag should look like this

<asp:datalist id="dllimage" runat="server">
<ItemTemplate>
<img id="star" runat="server" src="images/star.gif">
</ItemTemplate>
</asp:datalist>


and if you want to change the src on the server side(code behind) you must do the following

        Image myimage =(Image) Page.FindControl("star");


myimage.ImageUrl = "here you enter you new path";


Thank you for posting at DotnetFunda

Vuyiswa Maseko

Thank you for posting at Dotnetfunda
[Administrator]

Sudhir, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudhir on: 11/4/2009 [Member] Starter

Up
0
Down
i have written same code but error comming
CS0104: 'Image' is an ambiguous reference between 'System.Drawing.Image' and 'System.Web.UI.WebControls.Image'
pls suggest me any one better way.



Sudhir, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 11/4/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
in which line are you getting this Error

Thank you for posting at Dotnetfunda
[Administrator]

Sudhir, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudhir on: 11/4/2009 [Member] Starter

Up
0
Down
Image myimage =(Image) Page.FindControl("star");
above line giving error
CS0104: 'Image' is an ambiguous reference between 'System.Drawing.Image' and 'System.Web.UI.WebControls.Image'
pls suggest me any one better way.


Sudhir, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 11/4/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
ooh ok

change this line to


System.Drawing.Image myimage =(Image) Page.FindControl("star");


and try it again

Thank you for posting at Dotnetfunda

Vuyiswa Maseko


Thank you for posting at Dotnetfunda
[Administrator]

Sudhir, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudhir on: 11/4/2009 [Member] Starter

Up
0
Down
System.Drawing.Image myimage =(Image) Page.FindControl("star");
if i try above code then imageurl is not supporting.
pls suggest me what can i do.

Sudhir, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 11/4/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Today i have made a lot of mistakes, it shows that it was a long day , i was irritated by Sinuses and could not concerntrate for long, just asnwered some questions in passing. But here is your Final Answer
you have to use WEb.UI.Webcontrols because we are dealing with a control of that type.


System.Web.UI.WebControls.Image myimage = (System.Web.UI.WebControls.Image)Page.FindControl("star");

myimage.ImageUrl = "here you enter you new path";


Thank you for posting at Dotnetfunda

Vuyiswa Maseko

Thank you for posting at Dotnetfunda
[Administrator]

Sudhir, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response