techques
asked on
How to add if condition in a repeater?
Hi
I have a aspx page which uses repeater to list out query result.
There are 2 fileds: type and amount
I want to show that
if type = 1 or 2, add '+' prefix to amount
if type = 3 or 4, add '-' prefix to amount
e.g.
type=2, amount= +344,220.78
type=4, amount= -221,341.30
The following is the code to show those 2 fields.
Here is the psuedo code that I need:
asp:Label ID="amount" runat="server" Text='
if(<%# DataBinder.Eval(Container. DataItem, "type")%> == 1 || <%# DataBinder.Eval(Container. DataItem, "type")%> == 2)
{
"+"
}
if(<%# DataBinder.Eval(Container. DataItem, "type")%> == 3 || <%# DataBinder.Eval(Container. DataItem, "type")%> == 4)
{
"-"
}
<%# string.Format("{0:#,##0.00 }",DataBin der.Eval(C ontainer.D ataItem, "amount"))%>'></asp:Label>
I use C# and aspx.
I have a aspx page which uses repeater to list out query result.
There are 2 fileds: type and amount
I want to show that
if type = 1 or 2, add '+' prefix to amount
if type = 3 or 4, add '-' prefix to amount
e.g.
type=2, amount= +344,220.78
type=4, amount= -221,341.30
The following is the code to show those 2 fields.
Here is the psuedo code that I need:
asp:Label ID="amount" runat="server" Text='
if(<%# DataBinder.Eval(Container.
{
"+"
}
if(<%# DataBinder.Eval(Container.
{
"-"
}
<%# string.Format("{0:#,##0.00
I use C# and aspx.
<asp:Label ID="type" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "type")%>'></asp:Label>
<asp:Label ID="amount" runat="server" Text='<%# string.Format("{0:#,##0.00}",DataBinder.Eval(Container.DataItem, "amount"))%>'></asp:Label>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I did not understant the Mr Agile's code
I tried to use your code:
<%#(((int.Parse(DataBinder .Eval(Cont ainer.Data Item, "transactiontypeid")) > 2) ? "+" : "-") + string.Format("{0:#,##0.00 }",DataBin der.Eval(C ontainer.D ataItem, "amount"))) %>'></asp:Label>
But, it has compile error:
The best overloaded method match for 'int.Parse(string)' has some invalid arguments
It is the sql for the dataset:
select [id]=t.id, [transactiontypeid]=transa ctiontypei d, [type]=r.type, [clientid]=t.clientid, [nickname]=c.nickname, [currency]=t.currency, [ucurrency]=u.currency, [rate], [amount], [countervalue], [clientreference], [remarks]=t.remarks, [ashortcode]=a.shortcode+ '-' + a.currency + '-' + a.type, [handlingincome], [handlingexpense], [trandatetime], [status] from alltransaction t inner join client c on t.clientid = c.id inner join currency u on t.currency = u.currency inner join transactiontype r on t.transactiontypeid = r.id inner join account a on t.accountid = a.id where alltranid = 0 and t.clientid = '" + id + "' order by [id] asc
I tried to use your code:
<%#(((int.Parse(DataBinder
But, it has compile error:
The best overloaded method match for 'int.Parse(string)' has some invalid arguments
It is the sql for the dataset:
select [id]=t.id, [transactiontypeid]=transa
ASKER
I found that it cannot use int.Parse()
It works if I change to ConvertTo.Int32()
It works if I change to ConvertTo.Int32()
try the code below.
Open in new window