As Vino Jangle has pointed out you are doing the query for the column within the loop - what you actually need to do is get the list of columns that are selected into a comma-separated list and use that.
You should also be using Parameterized queries - never, ever concatenate strings to create sql commands.
Try this instead:
protected void Button2_Click(object sender, EventArgs e)
{
if (ListBox1.Items.Count > 0)
{
List<string> listbfrom = new List<string>();
for (int i = 0; i < ListBox1.Items.Count; i++)
if (ListBox1.Items[i].Selected)
listbfrom.Add(ListBox1.Items[i].Text);
string csv = string.Join(",", listbfrom);
con.Open();
string str = "SELECT @listbfrom FROM @tabfrom";
using (SqlCommand com = new SqlCommand(str, con))
{
com.Parameters.AddWithValue("@listbfrom", csv);
com.Parameters.AddWithValue("@tabfrom", DropDownList1.SelectedItem.Text);
DataSet dsBooking = new DataSet();
SqlDataAdapter dap = new SqlDataAdapter(com);
dap.Fill(dsBooking);
con.Close();
}
GridView1.DataSource = dsBooking;
GridView1.DataBind();
}
}
If you have further questions please do not include commented out code or empty methods. Only post the code you are having a problem with.
[EDIT] The solution above only works for .NET 4 and above. For .NET 3.5 replacing
string csv = string.Join(",", listbfrom);
with
string csv = string.Join(",", listbfrom.ToArray());