Checkbox and Radiobutton controls in Asp.Net

1)checkbox & radiobutton can be use accept Boolean type data[true/false]. Among collection of checkboxes user can select more than one checkbox.

2)among collection of radiobuttons with in a group, user can select only one radiobutton

 

Checkbox properties:

1)id-it should start with chk

2)Text-specify text to be displayed

3)checked-true/false

        It returns true if checkbox is selected else returns false

 

Radiobutton properties:

1)id-it should start with rbtn

2Text-specify text to be displayed

3)checked-true/false

4)groupname-it can be used to group related radiobuttons

 

Arranging controls using html table:

Arranging controls using absolute positioning(i.e drag&drop) doesn’t provide “what you see is what you get”, most of the times controls positioning will be changing at runtime (or) controls will be overlapping. The solution is arranging controls using html table for proper presentation.

->table is collection of rows

->row is collection of cells

->merging cells can be done using colspan

 

Creating website to work with checkbox and radiobutton

 

Goto visual studio

Start->run->devenv

It will display main window of visual studio

File menu->new->website->visual c#->select asp.net empty website

Weblocation->e:\aspnet\hotelsite[drive:\dir\websitename]

Visual studio create a folder with website name, in this folder website related files will be placed

 

Add webform

Goto view menu and select solution explorer

Right click on website path and select add new item

Select webform

Give name as register.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="display.aspx.cs" Inherits="display" %>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

   

    </div>

    </form>

</body>

</html>

 

Goto design part

Place table onto webform[register.aspx]

Goto table menu and select insert table

Rows-4, cols-2, bordersize-4

Size table, rows and cols according to requirement

 

Arranging controls with in a table:

Place label control into 1st row 1st col

->label1 properties

Text-name

Place textbox control into 1st row 2nd col

 

Name

 

Room type           deluxe            ordinary

                               A/c                  computer

register

 

        label                                         

 

radiobutton1 properties

text-delux

groupname-g1

 

radiobutton2 properties

text-ordinary

groupname-g1

 

checkbox1 properties

text-A/C

 

checkbox2 properties

text-computer

 

label3 properties

text-label3[remove default text]

 

double click on register button

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

 

public partial class register : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

 

    }

    protected void Button1_Click(object sender, EventArgs e)

    {

        int rent = 0, acost = 0;

        if (RadioButton1.Checked)

            rent = 1000;

        else if (RadioButton2.Checked)

            rent = 500;

        if (CheckBox1.Checked)

            acost = 300;

        if (CheckBox2.Checked)

            acost = acost + 200;

        int total = rent + acost;

        Label3.Text = "registered....<br> rent/day:" + total;

 

    }

}

 

Goto design view

Radiobutton1 properties

Tooltip-rent:1000

Radiobutton2 properties

Tooltip-rent:500

 

Goto contrl F5

 

Note:tooltip text will be displayed when mouse pointer is taken onto control.