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 }); }
When we are doing some editing operations, sometimes we have to empty all the textboxes after or in-between the operation. If user have entered all the values and save all the data, then programmer have to clear the textboxes to operate again.
Drag-n-drop some textboxes on the form and a button also. The text of all the textboxes is set to “Welcome”, we are going to be clear all these textboxes with some lines of c# code. The form is look like the below image:
In the click event of this button, write the following code:
In this c# code, the loop will exist till all the controls of this form. In the next line check the type of control, if the type is TextBox then set the text property to string.Empty. This code will set the text property to blank string for all the textboxes. And after it the form will look like the below image.
Using the same code we can set any value for any control having the same type. If we want to set some string to the textboxes then replace string.Empty to that string to be replaced.
Drag-n-drop some textboxes on the form and a button also. The text of all the textboxes is set to “Welcome”, we are going to be clear all these textboxes with some lines of c# code. The form is look like the below image:
In the click event of this button, write the following code:
foreach (var item in this.Controls)
{
if (item.GetType().Equals(typeof(TextBox)))
{
TextBox tb = item as TextBox;
tb.Text = string.Empty;
}
}
{
if (item.GetType().Equals(typeof(TextBox)))
{
TextBox tb = item as TextBox;
tb.Text = string.Empty;
}
}
In this c# code, the loop will exist till all the controls of this form. In the next line check the type of control, if the type is TextBox then set the text property to string.Empty. This code will set the text property to blank string for all the textboxes. And after it the form will look like the below image.
Using the same code we can set any value for any control having the same type. If we want to set some string to the textboxes then replace string.Empty to that string to be replaced.
Comments
Post a Comment