protected void GridView1_PageIndexChanging1(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = ds
GridView1.DataBind();
}
You can hold the data source in a variable so that you don't have to duplicate code to re populate the data source:
private DataSet GridView1DataSource
{
get
{
if(Session["gridview1datasource"] == null)
{
Session["gridview1datasource"] = new DataSet;
}
return (DataSet)Session["gridview1datasource"];
}
set
{
Session["gridview1datasource"] = value;
}
}
Then change the Button1_Click to be as follows:
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=RESTON-PC;Initial Catalog=Easy2Connect;Integrated Security=True");
con.Open();
string ret = "select * from SearchData where ClassName = '" + DropDownList2.SelectedItem + "'and City = '" + DropDownList3.SelectedItem + "'";
cmd = new SqlCommand(ret, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(GridView1DataSource);
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
}
All the best.