## 8 replies

Last post Jul 18, 2017 01:09 PM by kaushalparik27

• asp.ambur

Member

395 Points

1093 Posts

### how to set divide in my below query

Hello

This is my code

``` <%# ((Eval("Qty")!= DBNull.Value ? Convert.ToDouble(Eval("Qty")) : 0) *
(Eval("Rate")!= DBNull.Value ? Convert.ToDouble(Eval("Rate")) : 0)).ToString()%>```

I want to divided by 10 (Qty * Rate) / 10

how to do so using my above query

• umairaslam22

Contributor

2535 Points

842 Posts

### Re: how to set divide in my below query

Do it in SQL and name this column as Total then use this column alis in Eval.

Mathematics in strings and tags is not a good approach in future too , when you need to change or debug the results.

you cannot perform Basic math operations in string.

((Qty * Rate) / 10) Total

Then use Eval(Total)

Umair Aslam
MCP
Blog
• asp.ambur

Member

395 Points

1093 Posts

### Re: how to set divide in my below query

can it be possible to do using my given code if yes please give me the code with divide

• umairaslam22

Contributor

2535 Points

842 Posts

### Re: how to set divide in my below query

Take the values in C# , there you can do it.

Just give a try to Eval('Total*Rate').

Umair Aslam
MCP
Blog
• kaushalparik...

All-Star

31332 Points

7049 Posts

### Re: how to set divide in my below query

#### asp.ambur

want to divided by 10 (Qty * Rate) / 10

how to do so using my above query

Make sure you avoid divide by zero error:

```<%# ((Eval("Qty")!= DBNull.Value ? Convert.ToDouble(Eval("Qty")) : 0) *  (Eval("Rate")!= DBNull.Value ? Convert.ToDouble(Eval("Rate")) : 0) /
(((Eval("Qty")!= DBNull.Value ? Convert.ToDouble(Eval("Qty")) : 0) *  (Eval("Rate")!= DBNull.Value ? Convert.ToDouble(Eval("Rate")) : 0)) > 0 ? 10 : 0)).ToString()%>```

नमस्ते,
[KaushaL] Blog Twitter [MS MVP 2008 & 2009] [MCC 2011] [MVP Reconnect 2017]
Don't forget to click "Mark as Answer" on the post that helped you
• asp.ambur

Member

395 Points

1093 Posts

### Re: how to set divide in my below query

let us assume i have three Eval fields

1) Qty 2) Rate 3) NoOfData

and my code for Qty * Rate / NoOfData

i got Qty * Rate perfect by using this below code

` <asp:Label ID="LB" runat="server" Text='<%# ((Eval("Qty")!= DBNull.Value ? Convert.ToDouble(Eval("Qty")) : 0) *  (Eval("Rate")!= DBNull.Value ? Convert.ToDouble(Eval("Rate")) : 0)).ToString()%>'></asp:Label>`

now i want to divide ( NoOfData) how to do so

• kaushalparik...

All-Star

31332 Points

7049 Posts

### Re: how to set divide in my below query

#### asp.ambur

let us assume i have three Eval fields

1) Qty 2) Rate 3) NoOfData

and my code for Qty * Rate / NoOfData

i got Qty * Rate perfect by using this below code

` <asp:Label ID="LB" runat="server" Text='<%# ((Eval("Qty")!= DBNull.Value ? Convert.ToDouble(Eval("Qty")) : 0) *  (Eval("Rate")!= DBNull.Value ? Convert.ToDouble(Eval("Rate")) : 0)).ToString()%>'></asp:Label>`

now i want to divide ( NoOfData) how to do so

Use the same logic that you are writing for Qty and Rate:

```<%# ((Eval("Qty")!= DBNull.Value ? Convert.ToDouble(Eval("Qty")) : 0) *  (Eval("Rate")!= DBNull.Value ? Convert.ToDouble(Eval("Rate")) : 0) /
(((Eval("Qty")!= DBNull.Value ? Convert.ToDouble(Eval("Qty")) : 0) *  (Eval("Rate")!= DBNull.Value ? Convert.ToDouble(Eval("Rate")) : 0)) > 0 ?
(Eval("NoOfData")!= DBNull.Value ? Convert.ToDouble(Eval("NoOfData")) : 0) : 0)).ToString()%>```

नमस्ते,
[KaushaL] Blog Twitter [MS MVP 2008 & 2009] [MCC 2011] [MVP Reconnect 2017]
Don't forget to click "Mark as Answer" on the post that helped you
• asp.ambur

Member

395 Points

1093 Posts

### Re: how to set divide in my below query

error

Compiler Error Message: CS1002: ; expected

Source Error:

 ```Line 148: Line 149: ```
Line 150: Line 151:
• kaushalparik...

All-Star

31332 Points

7049 Posts

### Re: how to set divide in my below query

#### asp.ambur

error

Compiler Error Message: CS1002: ; expected

Source Error:

 ```Line 148: Line 149: ```
Line 150: Line 151:

You have an extra ) bracket that you need to remove:

`<asp:Label ID="LB" runat="server" Text='<%# (((Eval("Qty")!= DBNull.Value ? Convert.ToDouble(Eval("Qty")) : 0) *  (Eval("Rate")!= DBNull.Value ? Convert.ToDouble(Eval("Rate")) : 0)) > 0 ? (Eval("NoOfData")!= DBNull.Value ? Convert.ToDouble(Eval("NoOfData")) : 0) : 0).ToString()%>'></asp:Label>`

नमस्ते,
[KaushaL] Blog Twitter [MS MVP 2008 & 2009] [MCC 2011] [MVP Reconnect 2017]
Don't forget to click "Mark as Answer" on the post that helped you