Practical - 04

AIM: Design a web application using Radio Button and Check Box using ASP.Net through C# language.

How to open Visual Studio

Visual Studio Framework

Framework Introduction

Figure 1: Introduction of Visual Studio Framework.

Discussion

Here, the aim is to design a web application using radio button and checkbox. To understand the concept of these controls, we have taken an example of calculating fees of different subjects, first by using radio button and then by check box.

First let us understand,

What are radio button and check boxes?

Radio button is a control that is used to select single options out of multiple options whereas check box can be used to select multiple options among multiple options.

Design view of fee calculation using radio button is shown in figure 2. Here Total Fees shows the fees of a selected subject and can select only one option at any instance of time.

Here, by default all radio buttons can be selected at once, to make one selection at a time we have to edit a property "GroupName" of radio buttons and assign all radio buttons with single group name.
Design View of Fee calculation using radio button.

Design View

Figure 2: Design view of Fees calculation Web Form using radio button.

C# Code

C# code of GetFees button is shown below:

			
protected void Button1_Click(object sender, EventArgs e)
{
        int total = 0;
        if (RadioButton1.Checked)
        {
            total = 1000;
        }
        else if (RadioButton2.Checked)
        {
            total = 2000;
        }
        else if (RadioButton3.Checked)
        {
            total = 3000;
        }
        else if (RadioButton4.Checked)
        {
            total = 4000;
        }
        else if (RadioButton5.Checked)
        {
            total = 5000;
        }
        Label1.Text = "Rs. " + total.ToString() + "/-";
}
					

Design view of fee calculation using check box is shown in figure 3. Here Total Fees shows the sum fees of all selected subject.

Design View of Fee Calculation using Check-box.

Design View

Figure 3: Design view of Fees calculation Web Form using check box.

C# Code

C# code of GetFees button using check box is shown below:

			
protected void Button1_Click(object sender, EventArgs e)
{
        int total = 0;
        if (CheckBox1.Checked)
        {
            total += 1000;
        }
        if (CheckBox2.Checked)
        {
            total += 2000;
        }
        if (CheckBox3.Checked)
        {
            total += 3000;
        }
        if (CheckBox4.Checked)
        {
            total += 4000;
        }
        else if (CheckBox5.Checked)
        {
            total += 5000;
        }
        Label1.Text = "Rs. " + total.ToString() + "/-";
}
					

Points to Remember:

Theory of Computation AIM 01 Transition Diagram

Prepared By

Piyush Garg,
Asst. Professor,
Department of CSE, CIST
E-mail: piyushgarg1985@yahoo.com