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 }); }
Example of count List Item
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
string s = "Total item of the dropdownlist are<br/>";
s = s + DropDownList1.Items.Count;
string s1 = "Total item of the listbox are <br/>";
s1 = s1 + ListBox1.Items.Count;
Label1.Text = s + "<br/>" + s1;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<strong>HOW TO COUNT LISTITEM IN A DROPDOWNLIST</strong>
<br />
<asp:DropDownList ID="DropDownList1" runat="server" Height="46px" Width="133px">
<asp:ListItem>Item-1</asp:ListItem>
<asp:ListItem>Item-2</asp:ListItem>
</asp:DropDownList>
<br />
<strong>HOW TO COUNT LISTITEM IN A LISTBOX<br />
</strong>
<asp:ListBox ID="ListBox1" runat="server" Height="136px" Width="123px">
<asp:ListItem>ListItem-1</asp:ListItem>
<asp:ListItem>ListItem-2</asp:ListItem>
<asp:ListItem>ListItem-3</asp:ListItem>
<asp:ListItem>ListItem-4</asp:ListItem>
</asp:ListBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Count" />
<br />
<br />
<asp:Label ID="Label1" runat="server"></asp:Label>
<br />
<br />
</div>
</form>
</body>
</html>
Output
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
string s = "Total item of the dropdownlist are<br/>";
s = s + DropDownList1.Items.Count;
string s1 = "Total item of the listbox are <br/>";
s1 = s1 + ListBox1.Items.Count;
Label1.Text = s + "<br/>" + s1;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<strong>HOW TO COUNT LISTITEM IN A DROPDOWNLIST</strong>
<br />
<asp:DropDownList ID="DropDownList1" runat="server" Height="46px" Width="133px">
<asp:ListItem>Item-1</asp:ListItem>
<asp:ListItem>Item-2</asp:ListItem>
</asp:DropDownList>
<br />
<strong>HOW TO COUNT LISTITEM IN A LISTBOX<br />
</strong>
<asp:ListBox ID="ListBox1" runat="server" Height="136px" Width="123px">
<asp:ListItem>ListItem-1</asp:ListItem>
<asp:ListItem>ListItem-2</asp:ListItem>
<asp:ListItem>ListItem-3</asp:ListItem>
<asp:ListItem>ListItem-4</asp:ListItem>
</asp:ListBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Count" />
<br />
<br />
<asp:Label ID="Label1" runat="server"></asp:Label>
<br />
<br />
</div>
</form>
</body>
</html>
Comments
Post a Comment