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 }); }
Datagridview is the common control to bind our records in windows forms. I have bound this datagridview to dataset and in this article I will bind a list of student class’s data. I will use the same student class as in my previous post.
Drag-n-Drop a DataGridView on the form and write the following C# line of code in the constructor of the form.
Before running the project, just sure that you have inserted some items in the stuList. To insert some records we can use an in-built Add function of the list. Write the following code to insert records:
The record insertion should be done before the above binding. Run the project and the datagridview will be shown with these three records. The image shown the records in datagridview:
Drag-n-Drop a DataGridView on the form and write the following C# line of code in the constructor of the form.
public Form1()
{
InitializeComponent();
dataGridView1.DataSource = stuList;
}
{
InitializeComponent();
dataGridView1.DataSource = stuList;
}
Before running the project, just sure that you have inserted some items in the stuList. To insert some records we can use an in-built Add function of the list. Write the following code to insert records:
stuList.Add(new Student() { Name = "Jacob", Age = 29, City = "London", Dob = new DateTime(1983, 5, 26) });
stuList.Add(new Student() { Name = "Zulia", Age = 31, City = "London", Dob = new DateTime(1981, 5, 26) });
stuList.Add(new Student() { Name = "Brandon", Age = 35, City = "London", Dob = new DateTime(1978, 5, 26) });
stuList.Add(new Student() { Name = "Zulia", Age = 31, City = "London", Dob = new DateTime(1981, 5, 26) });
stuList.Add(new Student() { Name = "Brandon", Age = 35, City = "London", Dob = new DateTime(1978, 5, 26) });
The record insertion should be done before the above binding. Run the project and the datagridview will be shown with these three records. The image shown the records in datagridview:
Comments
Post a Comment