8 Replies - 1286 Views - Last Post: 05 May 2011 - 02:33 PM Rate Topic: ***** 1 Votes

#1 yasmeen1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 17-April 11

Sum of Label value

Posted 02 May 2011 - 06:51 PM

Hi,

I have label in which I display a table, as below:
 Label1.Text = "<table>";
            Label1.Text += "<tr>";
            Label1.Text += "<td> Date";
            Label1.Text += "</td>";
            Label1.Text += "<td>Result";
            Label1.Text += "</td>";
 while (dr.Read())
            {
                Label1.Text += "<tr>";
                Label1.Text += "<td>" + dr["date"];
                Label1.Text += "</td>";
               
                 if (st >= st1)
                {
                    double result = (st - st1);
                    if (Pair == "USD.CHF")
                    {
                           {
                               double pips = result * 100;
			     Label3.Text = Convert.ToString(pips);
						}		
                        
                    }
                else double pips = result * 100;
                             { 
			     Label3.Text = Convert.ToString(pips);
                              }
                Label1.Text += "<td>" + dr["pips"];
                Label1.Text += "</td>";
}




I have to Sum up all the pips in the loop and display in label.

Please help me.

Thanks
Yasmeen

MOD EDIT: Please use code tags when posting code.
:code:

This post has been edited by eclipsed4utoo: 03 May 2011 - 04:30 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Sum of Label value

#2 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1511
  • View blog
  • Posts: 5,916
  • Joined: 21-March 08

Re: Sum of Label value

Posted 03 May 2011 - 04:32 AM

So what problems are you running into? Are you getting errors? Is it not working correctly?
Was This Post Helpful? 0
  • +
  • -

#3 yasmeen1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 17-April 11

Re: Sum of Label value

Posted 03 May 2011 - 02:17 PM

No, Actually I don't know how to do that... Can you please give me any idea
Was This Post Helpful? 0
  • +
  • -

#4 SurfingShark  Icon User is offline

  • D.I.C Head

Reputation: 38
  • View blog
  • Posts: 188
  • Joined: 18-April 11

Re: Sum of Label value

Posted 03 May 2011 - 05:34 PM

Your variables are meaningless. What is "st" and "st1"?? Please post all the code, or at least those variable declarations. There is obviously some existing logic there, and it is almost impossible to follow it.
Was This Post Helpful? 0
  • +
  • -

#5 souptoy  Icon User is offline

  • D.I.C Head


Reputation: 54
  • View blog
  • Posts: 243
  • Joined: 17-January 08

Re: Sum of Label value

Posted 04 May 2011 - 08:39 AM

Besides the problem you're describing, I think it would be better if you used the HtmlTable, HtmlTableRow, and HtmlTableCell objects to create your table output and then place it in a placeholder; it will keep your code cleaner.

        HtmlTable table = new HtmlTable();
               
        while (readingData)
        {
            HtmlTableRow row = new HtmlTableRow();
            HtmlTableCell date = new HtmlTableCell();
            
            date.InnerText = DateTime.Today.ToShortDateString();
            row.Cells.Add(date);
            
            if(st >= st1) {
                
                HtmlTableCell cell = new HtmlTableCell();
                cell.InnerText = dr[pips] data goes here;
                row.Cells.Add(cell);
                table.Rows.Add(row);
            }
        }
        
        phPlaceHolder.Controls.Add(table);



As for the summation issue, I agree with SurfingShark...you need to give us some code.
Was This Post Helpful? 0
  • +
  • -

#6 yasmeen1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 17-April 11

Re: Sum of Label value

Posted 04 May 2011 - 03:48 PM

Thanks, But I have almost completed the project so It would be a huge work to change my table..

AS Summing up the field, I give some more info:

There is a label in which I get the data of the fields. It stores the data for every row. Lets say It has 4 rows, and for a particular field if I check the label, It stores vales like 4 5.5 8 0.01. Now I wanna add up these values and answer should be 17.51 i.e (4 + 5.5 + 8 + 0.01)

This field on which I have to apply SUM, its data does not come directly from database. I do some calculations and then put the values in the label for every row.

I hope it will help to undersatnd my issue.

Thanks
Yasmeen
Was This Post Helpful? 0
  • +
  • -

#7 souptoy  Icon User is offline

  • D.I.C Head


Reputation: 54
  • View blog
  • Posts: 243
  • Joined: 17-January 08

Re: Sum of Label value

Posted 05 May 2011 - 08:38 AM

This should sum up the values for you. You shouldn't have to store each value in a label until you get the sum.
        label1.Text = "<table>";
        label1.Text += "<tr>";
        label1.Text += "<td>Date</td>";
        label1.Text += "<td>Result</td>";
        label1.Text += "</tr>";

        double result = 0;
        double pips = 0;

        //no idea what st are or where they get their values 
        //but doing this so that the value evaluates to True
        double st = 2.5;
        double st1 = 1;
        int count = 1;
        string pPair = string.Empty;
        //end example variables

        //while (dr.Read())
        while (count <= 100)
        {
            label1.Text += "<tr>";
            //label1.Text += "<td>" + dr["date"] + "</td>";
            label1.Text += "<td>" + DateTime.Today.ToShortDateString() + "</td>";

            if (st >= st1)
            {
                result = (st - st1);

                if (pPair == "USD.CHF")
                {
                    pips += result * 100;
                }
                else
                {
                    pips += result * 100;
                }
                //label1.Text += "<td>" + dr["pips"] + "</td>";
                label1.Text += "<td>" + pips.ToString() + "</td>";
                label1.Text += "</tr>";
            }
            count++;
        }
        label3.Text = "Sum of all pips: " + pips.ToString();




Hope this answers your question
Was This Post Helpful? 1
  • +
  • -

#8 yasmeen1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 17-April 11

Re: Sum of Label value

Posted 05 May 2011 - 02:28 PM

Hey Thanks, It worked for me :)
Was This Post Helpful? 0
  • +
  • -

#9 souptoy  Icon User is offline

  • D.I.C Head


Reputation: 54
  • View blog
  • Posts: 243
  • Joined: 17-January 08

Re: Sum of Label value

Posted 05 May 2011 - 02:33 PM

Great! Please mark the post as helpful ;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1