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 }); }
In this article i will show you how to bind the dropdownlist to countries name. You can say load dropdownlist from countries names like United State, United Kingdom etc in asp.net c#. By the System.Globalization namespace you can bind dropdownlist to countries name in asp.net c#.
In previous article i explained some topics on dropdownlist:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" Height="28px" Width="118px"></asp:DropDownList>
</div>
</form>
</body>
</html>
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class BindCountries : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
List<string> countries = new List<string>();
CultureInfo[] culture = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
foreach (CultureInfo item in culture)
{
RegionInfo region = new RegionInfo(item.LCID);
if(!(countries.Contains(region.EnglishName)))
{
countries.Add(region.EnglishName);
}
}
countries.Sort();
DropDownList1.DataSource = countries;
DropDownList1.DataBind();
}
}
}
Above mentioned code define the following:
I have a list with string type, bind this English name of all countries name using System.Globalization namespace. First to bind array with the all cultures, now from all cultures you can get specific region.
In previous article i explained some topics on dropdownlist:
- Dropdownlist item with image in asp.net c#
- Tooltip on specific item of dropdownlist
- Bind dropdownlist with alphabets
- Validate dropdownlist in asp.net c#
Source code of this article:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="BindCountries.aspx.cs" Inherits="BindCountries" %><!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" Height="28px" Width="118px"></asp:DropDownList>
</div>
</form>
</body>
</html>
Code Behind:
using System;using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class BindCountries : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
List<string> countries = new List<string>();
CultureInfo[] culture = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
foreach (CultureInfo item in culture)
{
RegionInfo region = new RegionInfo(item.LCID);
if(!(countries.Contains(region.EnglishName)))
{
countries.Add(region.EnglishName);
}
}
countries.Sort();
DropDownList1.DataSource = countries;
DropDownList1.DataBind();
}
}
}
Above mentioned code define the following:
I have a list with string type, bind this English name of all countries name using System.Globalization namespace. First to bind array with the all cultures, now from all cultures you can get specific region.
Comments
Post a Comment