try
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList2.SelectedIndex != 0)
{
string columnName = DropDownList2.SelectedItem.Value;
string tableName ="Your_Table_Name";
string query = string.Format("select {0} from {1}", columnName, tableName);
cmd = new SqlCommand(query, con);
da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
Note: Take care of
SQL Injection[
^]