ARTICLE

CheckBox, CheckBoxList and DropDownList Controls in Asp.Net

Posted by Jitendra Sampathirao Articles | ASP.NET Programming November 16, 2010
Thia article is all about CheckBox, CheckBoxList and DropDownList.
Reader Level:

CheckBox and CheckBoxList are server controls in .Net.


Check boxes are an appropriate choice in situations where a radio button won't work. When deciding which control to use, when multiple selections are possible, we can use check boxes.

 

Check boxes allow the user to select a true or false condition.


We all have seen I accept Terms and Conditions with a check box when installing software.

 

DropDownList: A DropDownList is also a 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:

 

<!--[if !supportLists]-->1.       <!--[endif]-->Created DropDownList. And added list items.

<!--[if !supportLists]-->2.       <!--[endif]-->Depends on the selection of list item CheckboxList are shown.

<!--[if !supportLists]-->3.       <!--[endif]-->Select the CheckBoxList Items.

<!--[if !supportLists]-->4.       <!--[endif]-->When Click on the button 'submit', message will be shown.

 

DropDownList code:

 

<tr>

<td class="style1">

<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 class="style1">

<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 class="style1">

<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 class="style1">

<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 = "";

}

 

The Result is like this:


CHKDRP.bmp

 

Note: Source Code is available at Downloadload links.

 

I hope you like this article...

erver'>
Login to add your contents and source code to this article
post comment
     

sir i need d result like user name: scott courses offerd: cb c#.net ../ cb asp.net ../ cb vb.net cb sql server if scott selected c#.net and asp.net the result will be like " scott selected c#.net and asp.net" if no selection done result will be like " scott selected no check boxes" i need the prom here cb means CHECK BOX ../ means selected

Posted by munna bangla Mar 11, 2011

ya i cn understand it nd thx fr inform.....nd again thnx fr article

Posted by Amar Jeet Jan 31, 2011

yeah 1st link is not working..that's why i uploaded 2 nd one..Website admin has to delete that 1st link. they never done it till now...i dont have a preveliage to delete that 1st link... I hope you understand the problem...

Posted by Jitendra Sampathirao Jan 26, 2011

the frst link is broken that contain the name "CheckBoxList and DropDownList.zip" nd the second one is working that contain the name "CheckBox_ CheckBoxList_ DropDownList.zip " so user's can use the second 1 nd @Jitendra u sud hv to give the proper working link to dwnload the file fr other user's nd the article is much helpful fr me thnx fr upload.......Regards Amar

Posted by Amar Jeet Jan 25, 2011

Hi, Please send working link for this source code. Thanks in Advance Regards suhail

Posted by Suhail Jan 13, 2011
COMMENT USING
PREMIUM SPONSORS
DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and add new content to existing PDF documents from within your applications.
Get Career Advice from Experts
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.