Forum guidelines
AuthorQuestion
Aggreating set of marks in c# using asp
Posted By Chiranjeevi Aripaka on 07 Jan 2012
hi friends,

please help me in aggreating a set of marks .  in c# using asp


 
enter  marks
TEXTBOX1
54
TEXTBOX2 65
TEXTBOX3 86
TEXTBOX4 56
TEXTBOX5 25
TEXTBOX6 65
TEXTBOX7 86
total 437
aggreate 54.625
 THE VALUE ENTERED IN TEXTBOX 1 IS 54 ..... AND SO  ON



AuthorReply
Satyapriya Nayak
  • 1
  • 0
accepted
Re: Aggreating set of marks in c# using asp
Posted By Satyapriya Nayak on 07 Jan 2012   Accepted Answer
Hi chiranjeevi,

Try this...

protected void Button1_Click(object sender, EventArgs e)
{

 decimal a1 = System.Convert.ToDecimal(TextBox1.Text);
 decimal a2 = System.Convert.ToDecimal(TextBox2.Text);
 decimal a3 = System.Convert.ToDecimal(TextBox3.Text);
 decimal a4 = System.Convert.ToDecimal(TextBox4.Text);
 decimal a5 = System.Convert.ToDecimal(TextBox5.Text);
 decimal a6 = System.Convert.ToDecimal(TextBox6.Text);
 decimal a7 = System.Convert.ToDecimal(TextBox7.Text);
 decimal total = a1 + a2 + a3 + a4 + a5 + a6 + a7;
 TextBox8.Text = total.ToString();
 decimal agg = (total / 7);
 TextBox9.Text=agg.ToString();
}


Thanks

If this post helps you mark it as answer
Thanks

Re: Aggreating set of marks in c# using asp
Posted By Jignesh Trivedi on 08 Jan 2012  
hi,

Try following code.
in ASPX

<div runat="server" id="mytestdiv">
        <asp:TextBox runat="server" ID="txt1" ></asp:TextBox>
        <asp:TextBox runat="server" ID="txt2" ></asp:TextBox>
        <asp:TextBox runat="server" ID="txt3" ></asp:TextBox>
        <asp:TextBox runat="server" ID="txt4" ></asp:TextBox>
        <asp:TextBox runat="server" ID="txt5" ></asp:TextBox>
 ....
 ....
 ....
 ....
</div>

<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />

In CS

protected void Button1_Click(object sender, EventArgs e)
{
    double total=0;int count=0;
    foreach (var control in mytestdiv.Controls)
    {
        TextBox txtcontrol;
        txtcontrol = control as TextBox;
        if(txtcontrol !=null)
        {
            total += double.Parse(txtcontrol.Text);
            count++;
        }
    }
    double aggreate = total / count;
}

hope this help.


Re: Aggreating set of marks in c# using asp
Posted By Satyapriya Nayak on 09 Jan 2012  
Good code Jignesh :)

If this post helps you mark it as answer
Thanks

Re: Aggreating set of marks in c# using asp
Posted By Chiranjeevi Aripaka on 09 Jan 2012  
hi friend,


                   thank you so much.......

Re: Aggreating set of marks in c# using asp
Posted By Chiranjeevi Aripaka on 09 Jan 2012  
hi friend,


                   thank you so much.......

SPONSORED BY

Custom Software Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.