I want to show Components in a tabs , so first of all create few components. In this project we have three components, First View Component public class AllViewComponent : ViewComponent { private readonly UserManager<ApplicationUser> _userManager; public AllViewComponent(UserManager<ApplicationUser> userManager) { _userManager = userManager; } public async Task<IViewComponentResult> InvokeAsync() { List<StudentViewModel> allUsers = new List<StudentViewModel>(); var items = await _userManager.Users.ToListAsync(); foreach (var item in items) { allUsers.Add(new StudentViewModel {Id=item.Id, EnrollmentNo = item.EnrollmentNo, FatherName = item.FatherName, Name = item.Name, Age = item.Age, Birthdate = item.Birthdate, Address = item.Address, Gender = item.Gender, Email = item.Email }); }
The CheckBoxList Control
you can use a CheckBoxList control to display a number of check boxes at once as a column of check boxes. The CheckBoxList control exists within the System.Web.UI.WebControls namespace. This control is often useful when you want to bind the data from a datasource to checkboxes . The CheckBoxList control creates multiselection checkbox groups at runtime by binding these controls to a data source.Use of CheckBoxList Control
- Where you find multiple options.
- In Shoping Site where you find sub category under category
Example of CheckBoxList Control in ASP.NET
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
string s = "Your selected books are<br/>";
foreach (ListItem s1 in CheckBoxList1.Items)
{
if (s1.Selected)
{
s = s + s1.Text + "<br/>";
}
}
result.Text = s;
}
protected void Page_Load(object sender, EventArgs e)
{
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div >
Select Your Favorite books:<br />
<asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="True">
<asp:ListItem>ASP.NET </asp:ListItem>
<asp:ListItem>WINDOWS FORMS</asp:ListItem>
<asp:ListItem>WPF</asp:ListItem>
<asp:ListItem>WCF</asp:ListItem>
<asp:ListItem>JAVA SCRIPT</asp:ListItem>
</asp:CheckBoxList>
</div>
<asp:Label ID="result" runat="server"></asp:Label>
</form>
</body>
</html>
<!DOCTYPE html>
<script runat="server">
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
string s = "Your selected books are<br/>";
foreach (ListItem s1 in CheckBoxList1.Items)
{
if (s1.Selected)
{
s = s + s1.Text + "<br/>";
}
}
result.Text = s;
}
protected void Page_Load(object sender, EventArgs e)
{
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div >
Select Your Favorite books:<br />
<asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="True">
<asp:ListItem>ASP.NET </asp:ListItem>
<asp:ListItem>WINDOWS FORMS</asp:ListItem>
<asp:ListItem>WPF</asp:ListItem>
<asp:ListItem>WCF</asp:ListItem>
<asp:ListItem>JAVA SCRIPT</asp:ListItem>
</asp:CheckBoxList>
</div>
<asp:Label ID="result" runat="server"></asp:Label>
</form>
</body>
</html>
This example shows that you can choose multiple item in given list. Here foreach loop is running from starting index to ending imdex. When you select ASP.NET book item in the given list then your item will appear on the Label control under the CheckBoxList. If you again select Windows Forms Book in given list , PostBack will occurs and your result will appear on Label Control with previous result.
Comments
Post a Comment