This is a migrated thread and some comments may be shown as answers.

Trying to calculate percentage on the fly

1 Answer 287 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 10 Jul 2009, 06:08 PM
I have three textboxes(textbox1,textbox2,textbox4). Am trying to calculate the percentage of textbox1.value  to textbox3.value. Want to display the percentage in texbox4 on the fly. Is there an easy way to do this? it currently tells me the input string is not in correct format. Have tried numerous things. Any direction would be greatly appreciated. See code below.

Jason
 
            SqlConnection connSomsys = new SqlConnection(@"Server=cmdivst004\Jason08;Integrated Security=false;Database=QuoteDB; Persist Security Info=True;User ID=cmdiapp;Password=adiadmin");  
            SqlCommand selectCommand;  
            selectCommand = new SqlCommand("sprocgetQuoteProductTotals", connSomsys);  
            selectCommand.CommandType = CommandType.StoredProcedure;  
 
              
            SqlDataAdapter adapter = new SqlDataAdapter(selectCommand);  
            DataSet dataSet = new DataSet();  
            adapter.Fill(dataSet);  
            this.DataSource = dataSet;  
            this.DataMember = "Table";  
            this.textBox3.Value = dataSet.Tables[1].Rows[0][0].ToString();  
 
 
 
            
            int textbox1val;  
            int textbox3val;  
            textbox1val = Convert.ToInt32(this.textBox1.Value);  
            textbox3val = Convert.ToInt32(this.textBox3.Value);  
            decimal percent = (textbox1val * 100) / textbox3val;  
            string textbox4val = Convert.ToString(percent);  
              
            this.textBox4.Value = textbox4val;  
 



 

1 Answer, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 15 Jul 2009, 04:26 PM
Hi Jason,

Where is this code located? You're using definition report items, which means that it would be valid only if it is in the report constructor. However anything that can be calculated before the report processing has been started can be calculated on database level as well. The easiest way would be to add another column to your table which holds the calculated value and display it directly.

Sincerely yours,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
General Discussions
Asked by
Jason
Top achievements
Rank 1
Answers by
Steve
Telerik team
Share this question
or