I wanna share…

CheckBox, CheckBoxList and DropDownList Controls in Asp.Net

DownLoad Link: Click Here

CheckBox and CheckBoxList are server controls in .Net.

Checkboxes are an appropriate choice in situations where a radio button won’t work. When the choice to choose more than one option we can choose these controls.

Check box that allows the user to select a true or false condition.

We always seen I accept Terms and Conditions with a Checkbox when we installing Software’s.

DropDownList: A DropDownList is also commonly known as combo box. It can contain multiple data members, but unlike a normal list box the users can choose only one value from this control. Enables users to select from a single-selection drop-down list. The drop-down list can contain any number of items.

In my working project I used CheckBoxList Control for selecting skill set.

There is a dropdown list which is having options like MS technologies, Java Technologies, Databases, Operating systems, Web Designing tools etc.

Based on selected item we are showing CheckBoxList. If he selects MS Technologies we are showing MS related technologies using CheckBox List.

These are steps to know the process of given Example:

  1. Created DropDownList. And added list items.
  2. Depends on the selection of list item CheckboxList are shown.
  3. Select the CheckBoxList Items.
  4. When Click on the button ‘submit’, message will be shown.

DropDownList code:

<tr>

<td>

<asp:DropDownList ID=”ddlist” runat=”server” onselectedindexchanged= “ddltechs” AutoPostBack=”true”>

<asp:ListItem Text=”=SELECT=” Value=”SELECT”></asp:ListItem>

<asp:ListItem Text=”MS Technologies” Value=”MS Technologies”></asp:ListItem>

<asp:ListItem Text=”Java Technologies” Value=”Java Technologies”> </asp:ListItem>

<asp:ListItem Text=”Databases” Value=”Databases”></asp:ListItem>

</asp:DropDownList>

</td>

</tr>

CheckBoxList controls code:

/******For MS Technologies*****/

<tr id=”trMS” runat=”server” visible=”false”>

<td>

<asp:CheckBoxList ID=”MSTechTechnologies” runat=”server”>

<asp:ListItem Text=”ASP.Net” Value=”ASP.Net”></asp:ListItem>

<asp:ListItem Text=”ASP.Net” Value=”ASP.Net”></asp:ListItem>

<asp:ListItem Text=”C#.Net” Value=”C#.Net”></asp:ListItem>

<asp:ListItem Text=”VB.Net” Value=”VB.Net”></asp:ListItem>

<asp:ListItem Text=”J#.Net” Value=”J#.Net”></asp:ListItem>

<asp:ListItem Text=”WCF” Value=”WCF”></asp:ListItem>

<asp:ListItem Text=”WPF” Value=”WPF”></asp:ListItem>

<asp:ListItem Text=”Silverlight” Value=”Silverlight”></asp:ListItem>

</asp:CheckBoxList>

</td>

</tr>

/******For Java Technologies*******/

<tr id=”trJava” runat=”server” visible=”false”>

<td>

<asp:CheckBoxList ID=”JavaTech” runat=”server”>

<asp:ListItem Text=”Core Java” Value=”Core Java”></asp:ListItem>

<asp:ListItem Text=”J2SE” Value=”J2SE”></asp:ListItem>

<asp:ListItem Text=”J2EE” Value=”J2EE”></asp:ListItem>

<asp:ListItem Text=”JSP” Value=”JSP”></asp:ListItem>

<asp:ListItem Text=”SERVLET” Value=”SERVLET”></asp:ListItem>

<asp:ListItem Text=”EJB” Value=”EJB”></asp:ListItem>

<asp:ListItem Text=”JNDI” Value=”JNDI”></asp:ListItem>

</asp:CheckBoxList>

</td>

</tr>

/*******For DataBases*******/

<tr id=”trDB” runat=”server” visible=”false”>

<td>

<asp:CheckBoxList ID=”DataBases” runat=”server”>

<asp:ListItem Text=”SQL Server” Value=”SQL Server”></asp:ListItem>

<asp:ListItem Text=”Oracle” Value=”Oracle”></asp:ListItem>

<asp:ListItem Text=”MySql” Value=”MySql”></asp:ListItem>

<asp:ListItem Text=”DB2″ Value=”DB2″></asp:ListItem>

<asp:ListItem Text=”PostGreSQL” Value=”PostGreSQL”></asp:ListItem>

<asp:ListItem Text=”MS Access” Value=”MS Access”></asp:ListItem>

<asp:ListItem Text=”Informix” Value=”Informix”></asp:ListItem>

</asp:CheckBoxList>

</td>

</tr>

/******** When DropDownList Select Index Changed*******/

string list=””;

string chkvalue = Convert.ToString(hdnparameter.Value);

if (chkvalue == “SELECT”)

{

lblmsg.Text = “You should select Something::: “;

}

if (chkvalue == “MS Technologies”)

{

for (int index = 0; index < MSTechTechnologies.Items.Count; index++)

{

if (MSTechTechnologies.Items[index].Selected)

{

list = list + MSTechTechnologies.Items[index].Text + “,”;

}

}

}

else if (chkvalue == “Java Technologies”)

{

for (int index = 0; index < JavaTech.Items.Count; index++)

{

if (JavaTech.Items[index].Selected)

{

list = list + JavaTech.Items[index].Text + “,”;

}

}

}

else

{

for (int index = 0; index < DataBases.Items.Count; index++)

{

if (DataBases.Items[index].Selected)

{

list = list + DataBases.Items[index].Text + “,”;

}

}

}

lblmsg.Text = “You are having these skills:” + list;

lblmsg.Visible = true;

/******** When Button Click happens********/

value = (ddlist.SelectedItem.Value).Trim();

hdnparameter.Value = value;

if (value == “SELECT”)

{

lblmsg.Visible = true;

lblmsg.Text = “Please select”;

trMS.Visible = false;

trJava.Visible = false;

trDB.Visible = false;

}

else if (value == “MS Technologies”)

{

trMS.Visible = true;

trJava.Visible = false;

trDB.Visible = false;

lblmsg.Text = “”;

}

else if (value == “Java Technologies”)

{

trJava.Visible = true;

trMS.Visible = false;

trDB.Visible = false;

lblmsg.Text = “”;

}

else

{

trDB.Visible = true;

trMS.Visible = false;

trJava.Visible = false;

lblmsg.Text = “”;

}

Note: Source Code is available at Downloadload links.

I hope you like this article……….

Advertisements

Comments on: "CheckBox, CheckBoxList and DropDownList Controls in Asp.Net" (1)

  1. Hello! bkdafde interesting bkdafde site! I’m really like it! Very, very bkdafde good!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: