techques
asked on
How to add if(){}else{} to repeater databind in ASPX?
Hi
I use repeater to get and present the data. It shows fine. But, I want to display another text with certain condition, how can I do that?
Here is the code:
I use repeater to get and present the data. It shows fine. But, I want to display another text with certain condition, how can I do that?
Here is the code:
<%# Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(Convert.ToDecimal(DataBinder.Eval(Container.DataItem, "price")) * 2))).ToString() %>
How to change it to:
<%#
if( Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(Convert.ToDecimal(DataBinder.Eval(Container.DataItem, "bids")) * 2))) < 50)
{
print("Less than 50");
}
else
{
print("Larger than 50");
}
%>
simply make it as more standard wise like
<asp:Label CssClass="tds" ID="Label1" runat="server" Text='
CheckIfLarger(
Convert.ToInt32(Math.Ceili ng(Convert .ToDecimal (Convert.T oDecimal(D ataBinder. Eval(Conta iner.DataI tem, "price")) * 2))).ToString()
)
'></asp:Label>
then on the cs page write a function like
public string CheckIfLarger(string str)
{
if(Int.Parse(str)>50)
return("Larger than 50");
else
return("Less than 50");
}
<asp:Label CssClass="tds" ID="Label1" runat="server" Text='
CheckIfLarger(
Convert.ToInt32(Math.Ceili
)
'></asp:Label>
then on the cs page write a function like
public string CheckIfLarger(string str)
{
if(Int.Parse(str)>50)
return("Larger than 50");
else
return("Less than 50");
}
ASKER
I do not have label control, if the condition changes to
<=50 ? "Less than 50"
>50 && <=100 ? "Larger than 50 but smaller than 100"
>100 ? "Larger than 100"
How should the following code be changed?
<=50 ? "Less than 50"
>50 && <=100 ? "Larger than 50 but smaller than 100"
>100 ? "Larger than 100"
How should the following code be changed?
<%# (Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(Convert.ToDecimal(DataBinder.Eval(Container.DataItem, "bids")) * 2)))<50)? "Less than 50":"Larger than 50" %>
<%#
CheckIfLarger(
Convert.ToInt32(Math.Ceili ng(Convert .ToDecimal (Convert.T oDecimal(D ataBinder. Eval(Conta iner.DataI tem, "price")) * 2))).ToString()
)
%>
then on the cs page write a function like
CheckIfLarger(
Convert.ToInt32(Math.Ceili
)
%>
then on the cs page write a function like
public string CheckIfLarger(string str)
{
if(Int.Parse(str)>50)
return("Larger than 50");
else
return("Less than 50");
}
ASKER
But, it has 3 conditions:
<=50 ? "Less than 50"
>50 && <=100 ? "Larger than 50 but smaller than 100"
>100 ? "Larger than 100"
<=50 ? "Less than 50"
>50 && <=100 ? "Larger than 50 but smaller than 100"
>100 ? "Larger than 100"
just change the function
public string CheckIfLarger(string str)
{
if(Int.Parse(str)>100)
return("Larger than 100");
else if(Int.Parse(str)>50)
return("Larger than 50");
else
return("Less than 50");
}
ASKER
Int.Parse cannot be compiled in C#
I changed to convert.toint32, but it has run time error
I changed to convert.toint32, but it has run time error
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<%# (Convert.ToInt32(Math.Ceil
That is if you have a label control, the code will look like
<asp:Label CssClass="tds" ID="Label1" runat="server" Text='<%# (Convert.ToInt32(Math.Ceil