how can make a condition on datalist item template

Posted by Umeshdwivedi under ASP.NET on 8/11/2011 | Points: 10 | Views : 4464 | Status : [Member] | Replies : 2
hallo to all
i want condition in datalist template
i show image on condition
if find 1 value on database
then show image1
else
show image2
how can i do

Latest Technology Trainer
And Part time software consultant



Responses

Posted by: Hmanjarawala on: 8/11/2011 [Member] Bronze | Points: 25

Up
0
Down
you can do this like:

<TempleteColumn>
<asp:Image ID="img1" ImageUrl='<%# (Eval("YourColumn").ToString()==1)? "Image1-url": "Image2-url %>' runat="server" />
</TempleteColumn>

Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

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

Posted by: Ravindra.patil on: 8/11/2011 [Member] Starter | Points: 25

Up
0
Down
Hi
I Tried Hmanjarawala method its working...try to use same logic u will get ..
here is my code see this..it may help you .....

<asp:DataList ID="datalist1" runat="server" >
<ItemTemplate>
<asp:Image ID="img1" ImageUrl='<%# (Convert.ToInt32(Eval("RId"))==1)? "~/xyz.gif": "~/images.jpg" %>' Height="80px" Width="80px" runat="server" />
</ItemTemplate>
</asp:DataList>
RId is my ImageColumn Id Iam retriving Id from database.....

here is my C# Code
SqlConnection con1 = new SqlConnection("Data Source=xyz;Initial Catalog=xyz;User Id=xyz;Password=xyz");
con1.Open();
SqlDataAdapter adpt1 = new SqlDataAdapter("Select RId from EmpDetails", con1);

DataSet ds1 = new DataSet();
adpt1.Fill(ds1, "gfg");
datalist1.DataSource = ds1;
datalist1.DataBind();




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

Login to post response