Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hiiii,

i have write code lyk this

C#
protected void Page_Load(object sender, EventArgs e)
   {
       if (!this.IsPostBack)
       {
           double lowerrange = 0.1;
           double upperrange = 3.0;
           double lobound=0.1;
           double upbound=0.5;
           DataTable dt = new DataTable();
           dt.Columns.Add("Random Numbers", typeof(double));
           dt.Columns.Add("loss", typeof(double));
           Random random = new Random(Guid.NewGuid().GetHashCode());
           for (int i = 0; i < 1000; i++)
           {
               DataRow dr = dt.NewRow();
               dr["Random Numbers"] = random.NextDouble() * (upperrange-lowerrange) + lowerrange;
               dr["loss"] = random.NextDouble() * (upbound - lobound) + lobound;
               dt.Rows.Add(dr);

           }
           GridView1.DataSource = dt;
           GridView1.DataBind();
       }

and generate to random number coloum and now i want to add this column's value and get sum of that value at the end plz help me for this
and
also how can i get gain
i have equation gain = (randono/loss)*100.
and want to display in third column for each row.

plz help me......
Posted
Updated 24-Sep-14 18:20pm
v2
Comments
MuhammadUSman1 25-Sep-14 0:36am    
check solution if any issue then let me know.

1 solution

C#
//for sum of all values of one column, use following code
            var sumOfLoss = dt.Select().Sum(dr => Convert.ToDecimal(dr["loss"]));
            var sumOfRandom = dt.Select().Sum(dr => Convert.ToDecimal(dr["Random Numbers"]));//(loss,Random Numbers) your column name


if any issue then let me know

-> M.U
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900