Try this
<asp:dropdownlist id="DropDownList1" runat="server" autopostback="true" onselectedindexchanged="DropDownList1_SelectedIndexChanged" >
<asp:listitem>--select table--</asp:listitem>
<asp:listitem>Student</asp:listitem>
<asp:listitem>category</asp:listitem>
<asp:listitem>logindetails</asp:listitem>
</asp:dropdownlist>
<asp:gridview id="GridView1" runat="server" >
</asp:gridview>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
public partial class Default2 : System.Web.UI.Page
{
int iSIndex;
DataSet ds = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConnection con = new SqlConnection(@"Data Source=VICTORIN11-PC\\SQLEXPRESS;Initial Catalog=db;Integrated Security=True");
SqlDataAdapter da;
con.Open();
for (int i = 1; i < DropDownList1.Items.Count; i++)
{
string s = "select * from " + DropDownList1.Items[i].ToString();
da = new SqlDataAdapter(s, con);
da.Fill(ds, DropDownList1.Items[i].ToString());
}
ViewState["data"] = ds;
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
iSIndex = DropDownList1.SelectedIndex;
if (iSIndex > 0)
{
ds = (DataSet)ViewState["data"];
GridView1.DataSource = ds.Tables[iSIndex - 1];
GridView1.DataBind();
}
else
{
GridView1.DataSource = null;
GridView1.DataBind();
}
}
}