I have a dropdownlist ddlTables which contains the table names in my database and I display the table contents in the grid based on the table selected.
I am filling the data into my dropdownlist on Page_Load event using the following code:
ddlTables.Items.Add("-SELECT-");
String getTables = "SELECT TABLE_NAME FROM Information_Schema.Tables where Table_Type = 'BASE TABLE'";
MySqlConnection objMyCon10 = new MySqlConnection(strProvider);
objMyCon10.Open();
MySqlCommand cmd10 = new MySqlCommand(getTables, objMyCon10);
MySqlDataReader r = cmd10.ExecuteReader();
while (r.Read())
{
ddlTables.Items.Add(r[0].ToString());
}
objMyCon10.Close();
When I click Go button it should display the table contents of the table selected.
But on click of Go button, I have observed that it first calls the Page_Load event first and then calls btnGo_Click.
So it duplicates all the values in my dropdownlist.
Eventually each table name in my dropdownlist list appears twice after I click the Go button.
How to remove this duplication of the values?
Try putting that code into an
block