5 replies

Last post Oct 08, 2019 07:02 AM by samwu

• Gopi.MCA

Member

252 Points

584 Posts

Hello

How to add * 100 for this below

(row.FindControl("Label20") as Label).Text = "=PRODUCT(AB" + (dt.Rows.Count + 1).ToString() + "/J" + (dt.Rows.Count + 1).ToString()+")";

thanking you

• samwu

Contributor

3280 Points

1407 Posts

Re: add formula to my code

Hi Gopi.MCA,

Gopi.MCA

How to add * 100 for this below

Do you mean multiplying the code below by 100?

If so, which string do you want to *100? such as "dt.Rows.Count + 1", You can try to convert it type to int, then *100.

Convert.ToInt32(dt.Rows.Count + 1)*100

Best regards,

Sam

MSDN Community Support
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
• Gopi.MCA

Member

252 Points

584 Posts

Re: add formula to my code

Hi

I tried this

(row.FindControl("Label20") as Label).Text = "=PRODUCT(AD" + (dt.Rows.Count + 1).ToString() + "/J" + Convert.ToInt32(dt.Rows.Count + 1) * 100 + ")";

it showing after excel export

#DIV/0!

• samwu

Contributor

3280 Points

1407 Posts

Re: add formula to my code

Hi Gopi.MCA,

Please debug your code to find out where there is a problem.

This is my test result, dt.Rows.Count =3, then "Convert.ToInt32(dt.Rows.Count + 1) * 100" is equal to 400.

Best regards,

Sam

MSDN Community Support
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
• Gopi.MCA

Member

252 Points

584 Posts

Re: add formula to my code

Hi

This i used in convert to excel gridview

is this below code is right or wrong please let me know

first i take AD column then / with J then * 100 is this below code right or wrong

(row.FindControl("Label20") as Label).Text = "=PRODUCT(AD" + (dt.Rows.Count + 1).ToString() + "/J" + Convert.ToInt32(dt.Rows.Count + 1) * 100 + ")";

• samwu

Contributor

3280 Points

1407 Posts

Re: add formula to my code

Hi Gopi.MCA,

Gopi.MCA

first i take AD column then / with J then * 100 is this below code right or wrong

This depends on your requirement. If you want to splicing strings, then you can. But if you want to add, subtract, multiply and divide, then it is not possible.

You can try below code:

DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("CustomerId"), new DataColumn("Name"), new DataColumn("Country") });