I have a web form where there is one control list box and a data grid view to display data. Everything works fine when I open the app for the first time, the list box is also perfectly loaded and all the data is displayed in the data grid view.
But when I click the submit button, the listbox data is lost and also the latest data I have entered in the app is not showing in the grid view.
protected void Page_Load(object sender, EventArgs e)
{
try
{
if(!IsPostBack)
{
new M_DropDown().Get_Ward(lstTole);
GridCustomer.DataSource = new M_GetUser().GetCustomer();
GridCustomer.DataBind();
}
DataTable dt = new M_GetUser().GetCustomer();
GridCustomer.DataSource = dt;
GridCustomer.DataBind();
}
catch (Exception) { throw; }
}
On submit button click, I have cleared all the controls.
protected void btnSubmit_Click(object sender, EventArgs e)
{
// other code blocks ommitted
case "1":
lblMessage.Text = "customer added successfully!!!";
div_message.Visible = true;
div_message.Attributes.Add("class", "callout callout-info");
txtHouseNumber.Value = string.Empty;
txtName.Value = string.Empty;
txtCustId.Value = string.Empty;
txtCustContact.Value = string.Empty;
lstTole.Items.Clear();
break;
}
Why is it so? Why I am not getting the listbox data and last inserted data on successful button submit event?