Negitive and Positive value check

Posted by Nisar under ASP.NET on 2/1/2011 | Points: 10 | Views : 3095 | Status : [Member] | Replies : 6
Hi,

I have a variable "Amount" containing positive value and negitive value

I have 2 column with same name in asp.net datalist, one for positive values and one for negitive values.

i want that i check the value if value is negitive it should go in negitive column and if value is positive then it
should go in positive value column.

Here is asp.net code
<asp:DataList ID "dlist" runat="server">

<ItemTemplate>
<tr>
<td align="right"><%#Eval("Amount")%></td> // Positive value should go in this
<td align="right"><%#Eval("Amount")%></td> // negitive value should go in this
</tr>
</ItemTemplate>
</asp:DataList>

Looking for solution.
Regards
Nisar




Responses

Posted by: Pradsir on: 2/1/2011 [Member] Starter | Points: 25

Up
0
Down
Hi Nisar,

Is the Amount is a Column in Datatable in DataSet?

Thanks

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

Posted by: Nisar on: 2/1/2011 [Member] Starter | Points: 25

Up
0
Down

Hi,

I have generic List<> Object containing Amount field. Or it can be datatable.

But there is only one column Amount with positive and negitive values.

I want to display positive and negitive in two separate columns in DataList. as i mentioned above.

Thanks

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

Posted by: Pradsir on: 2/1/2011 [Member] Starter | Points: 25

Up
0
Down
I think We need to create 2 new Variables and assign their values as the + or - ve values.. & bind the new varibles in Datalist.

StrPosVariable = (Amount >0)? Amount: " ";
StrNegVariable = (Amount <0)? Amount: " ";

Thanks



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

Posted by: Karthikanbarasan on: 2/1/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Hi Nisar,

The option can be you can loop through the list of the datatable and arrange the positive and negative values in 2 different objects. Then map those objects to the different columns in the Datalist

Thanks
Karthik
www.f5Debug.net

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

Posted by: Madhu.b.rokkam on: 2/3/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
you need to do this way

in the aspx page add this

<asp:DataList ID="dlist" runat="server" onitemdatabound="dlist_ItemDataBound">
<ItemTemplate>
<tr>
<td align="right">
<%#GetPositive(Eval("Amount"))%>
</td>
<td align="right">
<%#GetNegative(Eval("Amount"))%>
</td>
</tr>
</ItemTemplate>
</asp:DataList>

and in the code behind u can add

protected void Page_Load(object sender, EventArgs e)
{
DataSet ds = new DataSet();
ds.ReadXml("data.xml"); // Read or fetch data from datatable
dlist.DataSource = ds.Tables[0];
dlist.DataBind();

}

protected object GetPositive(object n)
{
if(int.Parse(n.ToString()) > 0)
return n;
else
return null;
}

protected object GetNegative(object n)
{
if (int.Parse(n.ToString()) < 0)
return n;
else
return null;
}



Thanks and Regards
Madhu

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

Posted by: Nisar on: 2/5/2011 [Member] Starter | Points: 25

Up
0
Down
Thanks a lot. Problem resolved

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

Login to post response