0% found this document useful (0 votes)
39 views4 pages

ASP NET ListControls

---------------

Uploaded by

gvnbca
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views4 pages

ASP NET ListControls

---------------

Uploaded by

gvnbca
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Web Application using List Controls in ASP.

NET
(C#)

Aim
To develop a web application using List controls in [Link] (DropDownList, ListBox,
CheckBoxList, and RadioButtonList) with C# code-behind.

Procedure
1. Open Visual Studio and create a new [Link] Web Application (Web Forms) project.
2. Add a Web Form ([Link]) to the project.
3. Design the form using the following list controls:
- DropDownList → for single item selection.
- ListBox → for multiple selection.
- CheckBoxList → for multiple choice.
- RadioButtonList → for single choice.
4. Add a Button to trigger selection processing.
5. In the C# Code-Behind, write the logic inside the button click event to retrieve selected values.
6. Display results inside a Label.
7. Run the application and test it by making selections.

Program

[Link]
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="[Link]" Inherits="ListControl

<!DOCTYPE html>
<html xmlns="[Link]
<head runat="server">
<title>List Controls in [Link]</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>[Link] List Controls Example</h2>

<!-- DropDownList -->


<asp:Label ID="Label1" runat="server" Text="Select a Country:"></asp:Label>
<asp:DropDownList ID="ddlCountries" runat="server">
<asp:ListItem>India</asp:ListItem>
<asp:ListItem>USA</asp:ListItem>
<asp:ListItem>UK</asp:ListItem>
<asp:ListItem>Australia</asp:ListItem>
</asp:DropDownList>
<br /><br />

<!-- ListBox -->


<asp:Label ID="Label2" runat="server" Text="Select Your Skills:"></asp:Label>
<asp:ListBox ID="lstSkills" runat="server" SelectionMode="Multiple" Rows="5">
<asp:ListItem>C#</asp:ListItem>
<asp:ListItem>[Link]</asp:ListItem>
<asp:ListItem>SQL</asp:ListItem>
<asp:ListItem>JavaScript</asp:ListItem>
<asp:ListItem>Python</asp:ListItem>
</asp:ListBox>
<br /><br />

<!-- CheckBoxList -->


<asp:Label ID="Label3" runat="server" Text="Select Hobbies:"></asp:Label>
<asp:CheckBoxList ID="chkHobbies" runat="server">
<asp:ListItem>Reading</asp:ListItem>
<asp:ListItem>Traveling</asp:ListItem>
<asp:ListItem>Sports</asp:ListItem>
<asp:ListItem>Music</asp:ListItem>
</asp:CheckBoxList>
<br /><br />

<!-- RadioButtonList -->


<asp:Label ID="Label4" runat="server" Text="Select Gender:"></asp:Label>
<asp:RadioButtonList ID="rblGender" runat="server">
<asp:ListItem>Male</asp:ListItem>
<asp:ListItem>Female</asp:ListItem>
</asp:RadioButtonList>
<br /><br />

<!-- Submit Button -->


<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />

<br /><br />


<!-- Result -->
<asp:Label ID="lblResult" runat="server" ForeColor="Blue"></asp:Label>
</div>
</form>
</body>
</html>

[Link]
using System;
using [Link];

namespace ListControlsDemo
{
public partial class Default : [Link]
{
protected void Page_Load(object sender, EventArgs e)
{
}

protected void btnSubmit_Click(object sender, EventArgs e)


{
StringBuilder sb = new StringBuilder();

// DropDownList
[Link]("Country: " + [Link] + "<br/>");

// ListBox
[Link]("Skills: ");
foreach (var index in [Link]())
{
[Link]([Link][index].Text + " ");
}
[Link]("<br/>");

// CheckBoxList
[Link]("Hobbies: ");
foreach (var item in [Link])
{
var li = ([Link])item;
if ([Link])
{
[Link]([Link] + " ");
}
}
[Link]("<br/>");

// RadioButtonList
[Link]("Gender: " + [Link] + "<br/>");

[Link] = [Link]();
}
}
}

Output (Screen Layout)


-------------------------------------------
[Link] List Controls Example
-------------------------------------------
Select a Country: [India ▼]

Select Your Skills:


[ ] C#
[ ] [Link]
[ ] SQL
[ ] JavaScript
[ ] Python

Select Hobbies:
[ ] Reading [ ] Traveling
[ ] Sports [ ] Music

Select Gender:
(o) Male ( ) Female

[ Submit Button ]

-------------------------------------------
Result (after submit):
Country: India
Skills: C# [Link]
Hobbies: Reading Music
Gender: Male
-------------------------------------------

Result
Thus, a web application using List Controls (DropDownList, ListBox, CheckBoxList, and
RadioButtonList) in [Link] with C# was successfully created, executed, and tested.

You might also like