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 previous article we have already learn about bind label or text box using ado.net. Today, i will discuss about edmx file. If you want to bind label or text box in windows form, edmx file is the best solution for this type of problem. There are following steps to bind the label or text box:
I am giving you a whole code video for user friendly:
- First to add some label and text boxes in the form Like:
- Now, add edmx file in the solution
- Now, copy this code and paste in the button click event handler block.
private void button1_Click(object sender, EventArgs e)
{
int id = Convert.ToInt32(idtxt.Text);
Student_DBEntities dc = new Student_DBEntities();
var getrecord = dc.Student_record.Where(a => a.Id == id).SingleOrDefault();
Studentidtxt.Text = getrecord.Student_Id;
studentnametxt.Text = getrecord.Student_Name;
fathernametxt.Text = getrecord.Father_Name;
MotherNametxt.Text = getrecord.Mother_Name;
Addresstxt.Text = getrecord.Address;
}
Here,
- Student_DBEntities is a data context name, Create a object of that class, Access public property(Student_record -Screen Shot mentioned in the link) by using instance name.
- Access single record with the help of where clause with lambda expression also use SingleOrDefault( ) method.
- By using getrecord variable you can access table fields or you can say model class fields.
- Get each fields which is required by you, returning result assign in Text boxes.
Comments
Post a Comment