Hello
Can somebody please help me with the paging in a grid-view.
please find my code below
i understand that I am missing something very important here..but do not know what it is.
I get the search results normally. but when I click on the page number 2..the page refreshes and all the results are gone.
Also I was unable to figure out how can I display the message that there are no search results if the stored procedure returns no rows.
looking forward for help
thanks in advance
Can somebody please help me with the paging in a grid-view.
please find my code below
Code:
SqlDataAdapter sda = new SqlDataAdapter();
DataTable dt = new DataTable();
protected void search_Click(object sender, EventArgs e)
{
string connstring = System.Configuration.ConfigurationManager.ConnectionStrings["xxxxxxxxxx"].ConnectionString;
SqlConnection conn = new SqlConnection(connstring);
SqlCommand cmd = new SqlCommand("sp_xxxxxx_New");
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = conn;
cmd.Parameters.AddWithValue("@city", city.Text);
cmd.Parameters.AddWithValue("@state_abbrev", state.SelectedValue);
sda.SelectCommand = cmd;
sda.Fill(dt);
GridView.DataSource = dt;
GridView.DataBind();
}
protected void GridView_PageIndexChanging(Object sender, GridViewPageEventArgs e)
{
GridView.PageIndex = e.NewPageIndex;
//sda.Fill(dt);
GridView.DataSource = dt;
GridView.DataBind();
}
I get the search results normally. but when I click on the page number 2..the page refreshes and all the results are gone.
Also I was unable to figure out how can I display the message that there are no search results if the stored procedure returns no rows.
looking forward for help
thanks in advance