Answered by:
How can I share in the eval?

Question
-
User643189141 posted
Hi, How can I share in the eval? thanks.
How would you share with Eval ("column") / 3?
If the column value of 45 / 3, lists the value of 15,
Is it possible to share with the asp Eval ("column") / 3?Thursday, November 4, 2010 3:17 AM
Answers
-
User-231977777 posted
hi
look at this example :
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <asp:GridView ID="GridView1" runat="server"> <Columns> <asp:TemplateField HeaderText="Some"> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# ((float.Parse(Eval("Even").ToString())) / 3).ToString("0.0") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> <div> </div> </form> </body> </html>
code behind :protected void Page_Load(object sender, EventArgs e) { var some =from q in Enumerable.Range(1, 100).AsEnumerable () where q % 2 == 0 select new { Even =q }; GridView1.DataSource = some; GridView1.DataBind(); }
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, November 4, 2010 3:52 AM -
User-231977777 posted
Thank you it works.
Why, if the value is 0, displays such signs: NaN?
If the value is zero, the write 0.00.hi
you get that becouse you divide by Zero so you can use something like this :
<asp:Label ID="Label3" runat="server" Text='<%#(int) Eval("Even") > 0 && (int)Eval("odd") > 0 ? ((double.Parse(Eval("Even").ToString())) / (double.Parse(Eval("odd").ToString()))).ToString("0.0"): "0.00" %>'></asp:Label>
also another way) you can check cell text in GridView RowDataBound Event and replaced with New Text.thanks
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, November 4, 2010 6:56 AM
All replies
-
User-231977777 posted
hi
look at this example :
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <asp:GridView ID="GridView1" runat="server"> <Columns> <asp:TemplateField HeaderText="Some"> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# ((float.Parse(Eval("Even").ToString())) / 3).ToString("0.0") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> <div> </div> </form> </body> </html>
code behind :protected void Page_Load(object sender, EventArgs e) { var some =from q in Enumerable.Range(1, 100).AsEnumerable () where q % 2 == 0 select new { Even =q }; GridView1.DataSource = some; GridView1.DataBind(); }
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, November 4, 2010 3:52 AM -
User643189141 posted
Thanks, it works.
How about instead of three, I would like in the second column to calculate the value?
Something like:Text='<%# Bind("CelaDnevnica", "{0:N} €" ) %>'></asp:Label> (<asp:Label ID="Label90" runat="server" Text='<%# Eval("CelaDnevnicaStevilo") %>'></asp:Label>x<asp:Label ID="Label13" runat="server" Text='<%# ((float.Parse(Eval("CelaDnevnica").ToString())) / (float.Parse(Eval("Number).ToString()).ToString("0.0") %>'></asp:Label>€)
Thursday, November 4, 2010 4:17 AM -
User-231977777 posted
hi
use this :
<asp:Label ID="Label3" runat="server" Text='<%# ((double.Parse(Eval("Even").ToString())) / (double.Parse(Eval("odd").ToString()))).ToString("0.0") %>'></asp:Label>
thanksThursday, November 4, 2010 4:31 AM -
User643189141 posted
Thank you it works.
Why, if the value is 0, displays such signs: NaN?
If the value is zero, the write 0.00.Thursday, November 4, 2010 5:14 AM -
User-231977777 posted
Thank you it works.
Why, if the value is 0, displays such signs: NaN?
If the value is zero, the write 0.00.hi
you get that becouse you divide by Zero so you can use something like this :
<asp:Label ID="Label3" runat="server" Text='<%#(int) Eval("Even") > 0 && (int)Eval("odd") > 0 ? ((double.Parse(Eval("Even").ToString())) / (double.Parse(Eval("odd").ToString()))).ToString("0.0"): "0.00" %>'></asp:Label>
also another way) you can check cell text in GridView RowDataBound Event and replaced with New Text.thanks
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, November 4, 2010 6:56 AM -
User643189141 posted
thanks.
Thursday, November 4, 2010 12:09 PM -
User643189141 posted
'<%#(int) Eval("CelaDnevnica") > 0 && (int)Eval("CelaDnevnicaStevilo") > 0 ? ((double.Parse(Eval("CelaDnevnicaStevilo").ToString())) / (double.Parse(Eval("CelaDnevnica").ToString()))).ToString("0.0"): "0.00" %>'
Error:
Sys.WebForms.PageRequestManagerServerErrorException: Specified cast is not valid.
Thursday, November 4, 2010 12:16 PM -
User643189141 posted
now is work,
(int) =(decimal)
thanks
Thursday, November 4, 2010 12:32 PM