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 }); }
Introduction
The Partitioning operators in LINQ are used to divide an input sequence into two sections, without rearranging the elements, and then returning the result set with one of the sections that satisfies the given condition. The Take, Skip, TakeWhile, and SkipWhile clauses are referred to as the Partitioning operators. The Take clause takes the elements up to a specified position in a sequence. The TakeWhile clause takes the elements based on the specified function until an element does not satisfy the given condition.
The syntax of the Take clause is:
For C#
public static IEnumerabIe<T> Take<T>( this IEnumerabIe<T> source, int count);
The syntax of the Skip clause is:
For C#
public static IEnumerable<T> Skip<T>( this IEnumerab!e<T> source, int count);
<div>
<asp:ListBox ID="ListBox1" runat="server" Height="134px" Width="197px">
</asp:ListBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text=" Partitioning Operator Linq" />
</div>
Code Behind code
protected void Button1_Click(object sender, EventArgs e){
string[] fruits = { "apple", "banana", "pineapple", "papaya", "blueberry", "cheery" };
int size = 5;
int pages = (int)Math.Ceiling(fruits.Count() / (double)size);
for (int page = 0; page <pages; page++)
{
ListBox1.Items.Add("page " + page + ":");
var names = (from p in fruits
orderby p descending
select p).Skip(page * size).Take(size);
foreach (var name in names)
{
ListBox1.Items.Add(name);
}
}
}
Code Generate the following output
Comments
Post a Comment