Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Aug 09, 2012 07:56 AM by superguppie
Participant
792 Points
551 Posts
Aug 04, 2012 06:52 PM|LINK
Hi,
i have datalist define on my page, i just want to add the if else on itemtempalte can any one help me.
my code is somehting like this
<%# if (Eval("datavale") == "C" )%>
<div class="getfundiv" id="getfunction">
<span><a href="asdasd">test</a>
<% else %>
<div class="getfundiasdv" id="getfunasdction">
<span>some othwer code here </span>
</test>
how i can set this? how to set the condition <%# if (Eval("datavale") == "C" )%>
Contributor
3732 Points
1275 Posts
Aug 05, 2012 02:44 AM|LINK
Just plz make a function to include this very complicated things as output value, something like this:
public string Auto(string datavalue) { if(datavalue=="C") { return "<div class="getfundiv" id="getfunction"><span><a href="asdasd">test</a>"; } return "<div class="getfundiasdv" id="getfunasdction"><span>some othwer code here </span></test>"; } Then
<%#Auto(Eval("BoundField").ToString())%>
Aug 05, 2012 05:28 AM|LINK
hi,
yes i know that , but if i want to add the condition on aspx page can i do like this way
<%# if Eval("CCode") == "C" {%>
<div>asdasdsad</div>
<%} else {%>
<div>asdasd</div>
<%}%>
can i do like this way. thx
All-Star
42975 Points
7025 Posts
MVP
Aug 05, 2012 12:59 PM|LINK
Hello,
kirank28 but if i want to add the condition on aspx page can i do like this way
Yes you can do that. Check the sample app I've created for you
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> </head> <body> <form id="form1" runat="server"> <div style="float: left"> <%if (true) { %> <div> asdasdsad</div> <%} else { %> <div> asdasd</div> <%} %> </form> </body> </html>
Please 'Mark as Answer' if this post helps you.
Aug 05, 2012 05:20 PM|LINK
Hi, i think your not getting my question properly
how i can check the Eval value with the match keyword "C"
i think this is not a proper way to do ? so just let me know how i can check the eval value with the keyword "C"
Aug 06, 2012 05:10 AM|LINK
kirank28 Hi, i think your not getting my question properly how i can check the Eval value with the match keyword "C" <%# if Eval("CCode") == "C" {%> i think this is not a proper way to do ? so just let me know how i can check the eval value with the keyword "C"
For data-binding, you have to do what I've shown to u……
Star
10411 Points
1196 Posts
Aug 06, 2012 06:32 AM|LINK
Hi, you can use the following codes:
<asp:Literal ID="Literal1" runat="server" Text='<%# Eval("CCode").ToString()== "C" ? "asdasdsad" : "asdasd"%>'>
</asp:Literal>
Aug 07, 2012 09:29 AM|LINK
Allen Li - MSFT Hi, you can use the following codes: <asp:Literal ID="Literal1" runat="server" Text='<%# Eval("CCode").ToString()== "C" ? "asdasdsad" : "asdasd"%>'> </asp:Literal>
Greate!
Aug 07, 2012 11:01 AM|LINK
Hi, yes this is the one way to do.
but lets say i have two div then how i can set the condition of it for ex.
if condition
<div>
<asp:textbox id="asd" run="Server">
<asp:gridview runat =server ">.......</asp:gridview>
<asp:lable>.................
<%else%>
<asp:grdiview>....</>
<%end if%>
how i can set this condition using literal.
922 Points
257 Posts
Aug 07, 2012 11:06 AM|LINK
HTML
<asp:DataList runat="server"> <ItemTemplate> <%# GetText(Container.DataItem) %> </ItemTemplate> </asp:DataList>
And the code-behind: protected static string GetText(object dataItem) { if (Convert.ToBoolean(DataBinder.Eval(dataItem, "Deleted")) return "Deleted"; return "Not Deleted"; }
http://stackoverflow.com/questions/264400/datalist-conditional-statements-in-itemtemplate
kirank28
Participant
792 Points
551 Posts
if else in datalist bound
Aug 04, 2012 06:52 PM|LINK
Hi,
i have datalist define on my page, i just want to add the if else on itemtempalte can any one help me.
my code is somehting like this
<%# if (Eval("datavale") == "C" )%>
<div class="getfundiv" id="getfunction">
<span><a href="asdasd">test</a>
<% else %>
<div class="getfundiasdv" id="getfunasdction">
<span>some othwer code here </span>
</test>
how i can set this? how to set the condition <%# if (Eval("datavale") == "C" )%>
TimoYang
Contributor
3732 Points
1275 Posts
Re: if else in datalist bound
Aug 05, 2012 02:44 AM|LINK
Hi,
Just plz make a function to include this very complicated things as output value, something like this:
public string Auto(string datavalue) { if(datavalue=="C") { return "<div class="getfundiv" id="getfunction"><span><a href="asdasd">test</a>"; } return "<div class="getfundiasdv" id="getfunasdction"><span>some othwer code here </span></test>"; } Then<%#Auto(Eval("BoundField").ToString())%>kirank28
Participant
792 Points
551 Posts
Re: if else in datalist bound
Aug 05, 2012 05:28 AM|LINK
hi,
yes i know that , but if i want to add the condition on aspx page can i do like this way
<%# if Eval("CCode") == "C" {%>
<div>asdasdsad</div>
<%} else {%>
<div>asdasd</div>
<%}%>
can i do like this way. thx
Ruchira
All-Star
42975 Points
7025 Posts
MVP
Re: if else in datalist bound
Aug 05, 2012 12:59 PM|LINK
Hello,
Yes you can do that. Check the sample app I've created for you
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> </head> <body> <form id="form1" runat="server"> <div style="float: left"> <%if (true) { %> <div> asdasdsad</div> <%} else { %> <div> asdasd</div> <%} %> </form> </body> </html>
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.kirank28
Participant
792 Points
551 Posts
Re: if else in datalist bound
Aug 05, 2012 05:20 PM|LINK
Hi, i think your not getting my question properly
how i can check the Eval value with the match keyword "C"
<%# if Eval("CCode") == "C" {%>
i think this is not a proper way to do ? so just let me know how i can check the eval value with the keyword "C"
TimoYang
Contributor
3732 Points
1275 Posts
Re: if else in datalist bound
Aug 06, 2012 05:10 AM|LINK
For data-binding, you have to do what I've shown to u……
Allen Li - M...
Star
10411 Points
1196 Posts
Re: if else in datalist bound
Aug 06, 2012 06:32 AM|LINK
Hi, you can use the following codes:
<asp:Literal ID="Literal1" runat="server" Text='<%# Eval("CCode").ToString()== "C" ? "asdasdsad" : "asdasd"%>'>If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
TimoYang
Contributor
3732 Points
1275 Posts
Re: if else in datalist bound
Aug 07, 2012 09:29 AM|LINK
Greate!
kirank28
Participant
792 Points
551 Posts
Re: if else in datalist bound
Aug 07, 2012 11:01 AM|LINK
Hi, yes this is the one way to do.
but lets say i have two div then how i can set the condition of it for ex.
if condition
<div>
<asp:textbox id="asd" run="Server">
<asp:gridview runat =server ">.......</asp:gridview>
<asp:lable>.................
<%else%>
<asp:grdiview>....</>
<%end if%>
how i can set this condition using literal.
Vivek J Pand...
Participant
922 Points
257 Posts
Re: if else in datalist bound
Aug 07, 2012 11:06 AM|LINK
HTML
<asp:DataList runat="server">
<ItemTemplate>
<%# GetText(Container.DataItem) %>
</ItemTemplate>
</asp:DataList>
And the code-behind: protected static string GetText(object dataItem) { if (Convert.ToBoolean(DataBinder.Eval(dataItem, "Deleted")) return "Deleted"; return "Not Deleted"; }http://stackoverflow.com/questions/264400/datalist-conditional-statements-in-itemtemplate
--Vivek