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 }); }
Using the LINQ subset array you can print element of array at specific position through Skip( ) method. If you want to print array element at position number 3 then you should skip three starting index of array. Like
ArrayName .Skip(3).Take(2).ToArray( ) .
<div>
<asp:Button ID="Button1" runat="server" Height="33px" onclick="Button1_Click"
Text="Button" Width="96px" />
</div>
<p style="width: 118px">
<asp:Label ID="Label1" runat="server" Height="40px" Text="Label" Width="100px"></asp:Label>
</p>
</form>
{
string[] Vegetables = new string[]
{
"Tomato",
"Potato",
"Onion",
"Carrot",
"Sweet-Potato",
"Locky"
};
Label1.Text = "Vegetables array...<br />";
foreach (string Vegetable in Vegetables)
{
Label1.Text += Vegetable + "<br />";
}
string[] arraySubset = Vegetables.Skip(3).Take(2).ToArray();
Label1.Text += "<br />Vegetables sub array [element after 3 and count 2]...<br />";
foreach (string Vegetable in arraySubset)
{
Label1.Text += Vegetable + "<br />";
}
ArrayName .Skip(3).Take(2).ToArray( ) .
Source
<form id="form1" runat="server"><div>
<asp:Button ID="Button1" runat="server" Height="33px" onclick="Button1_Click"
Text="Button" Width="96px" />
</div>
<p style="width: 118px">
<asp:Label ID="Label1" runat="server" Height="40px" Text="Label" Width="100px"></asp:Label>
</p>
</form>
Business Logic Code
protected void Button1_Click(object sender, EventArgs e){
string[] Vegetables = new string[]
{
"Tomato",
"Potato",
"Onion",
"Carrot",
"Sweet-Potato",
"Locky"
};
Label1.Text = "Vegetables array...<br />";
foreach (string Vegetable in Vegetables)
{
Label1.Text += Vegetable + "<br />";
}
string[] arraySubset = Vegetables.Skip(3).Take(2).ToArray();
Label1.Text += "<br />Vegetables sub array [element after 3 and count 2]...<br />";
foreach (string Vegetable in arraySubset)
{
Label1.Text += Vegetable + "<br />";
}
Comments
Post a Comment