I have a button to display the records or information about customers ,the problem I just noticed that when I select a customer who has provided all the necessary information , the information about that particular customer is displayed properly , now when I try to display another customers information who has some missing fields , that time the missing field of this particular customer is replaced by the previous customers infomration , that means I need a way to clear the textboxes before I display customers information.Here is the method that I have to display the information.
public void ShowCustomerInformationCat1()
{
if (customer.cCustomerType != null)
{
ModifyCustomerByCategoryddlCustomerType.SelectedIndex = ModifyCustomerByCategoryddlCustomerType.Items.IndexOf(ModifyCustomerByCategoryddlCustomerType.Items.FindByText(customer.cCustomerType.Trim()));
ModifyCustomerByCategoryddlNewCustomerType.SelectedIndex = ModifyCustomerByCategoryddlNewCustomerType.Items.IndexOf(ModifyCustomerByCategoryddlNewCustomerType.Items.FindByText(customer.cCustomerType.Trim()));
}
if (customer.cInitial != null)
{
ModifyCustomerByCategoryddlInitial.SelectedIndex = ModifyCustomerByCategoryddlInitial.Items.IndexOf(ModifyCustomerByCategoryddlInitial.Items.FindByText(customer.cInitial.Trim()));
ModifyCustomerByCategoryddlNewInitial.SelectedIndex = ModifyCustomerByCategoryddlNewInitial.Items.IndexOf(ModifyCustomerByCategoryddlNewInitial.Items.FindByText(customer.cInitial.Trim()));
}
if (customer.cGender != null)
{
ModifyCustomerByCategoryddlGender.SelectedIndex = ModifyCustomerByCategoryddlGender.Items.IndexOf(ModifyCustomerByCategoryddlGender.Items.FindByText(customer.cGender.Trim()));
ModifyCustomerByCategoryddlNewGender.SelectedIndex = ModifyCustomerByCategoryddlNewGender.Items.IndexOf(ModifyCustomerByCategoryddlNewGender.Items.FindByText(customer.cGender.Trim()));
}
if (customer.cCountry != null)
{
ModifyCustomerByCategoryddlCountry.SelectedIndex = ModifyCustomerByCategoryddlCountry.Items.IndexOf(ModifyCustomerByCategoryddlCountry.Items.FindByText(customer.cCountry.Trim()));
ModifyCustomerByCategoryddlNewCountry.SelectedIndex = ModifyCustomerByCategoryddlNewCountry.Items.IndexOf(ModifyCustomerByCategoryddlNewCountry.Items.FindByText(customer.cCountry.Trim()));
}
}
Can anybody suggest me how to clear the textboxes , I dont want to clear them individually. Thanks for any suggestions.
foreach (var item in Page.Controls)
{
if (item is TextBox)
{
((TextBox)item).Text = "";
}
}
try like this.
foreach (var obj in Page.Controls.OfType<TextBox>())
{
obj.Text="";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With