Make sure you have set Gridview1.AllowPaging=True;
Then merge your LoadData(); BindGridView(); PriceList(); to One single function like
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindGridView();
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
BindGridView();
}
protected void BindGridView()
{
string strCmd ="SELECT ID, Name, Address, Email, Mobile, Category,Price FROM PostTable WHERE (Category=@Category OR @Category IS NULL) ";
if (DropDownList2.SelectedItem.Text == "Price: High To Low")
strCmd=strCmd+"order by price desc";
else if (DropDownList2.SelectedItem.Text == "Price: Low To High")
strCmd=strCmd+"order by price asc";
else
strCmd=strCmd+"order by id desc";
using(SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
{
using(SqlDataAdapter adap = new SqlDataAdapter(strCmd,con))
{
if (DropDownList1.SelectedItem.Text == "--Select--")
adap.SelectCommand.Parameters.Add("@Category",SqlDbType.NVarChar,50).Value=DBNull.Value;
else if (DropDownList1.SelectedItem.Text == "Mobiles")
adap.SelectCommand.Parameters.Add("@Category",SqlDbType.NVarChar,50).Value=DropDownList1.SelectedItem.Text;
using(DataTable dtbl =new DataTable())
{
adap.Fill(dtbl);
GridView1.DataSource = dtbl;
GridView1.DataBind();
}
}
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
BindGridView();
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
BindGridView();
}