public partial class Ahma_Accounting : System.Web.UI.Page { SqlCommand cmd = new SqlCommand(); protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { LoadData(); BindGridView(); ddd(); } if (!IsPostBack) { try { Userid.Value = Session["ID"].ToString(); } catch { } } } private void LoadData() { SqlConnection constr = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); string query = "SELECT ID, ContactPhoto, Price, City, Date FROM DetailsTable where type='Accounting' and city='Ahmedabad'"; SqlDataAdapter da = new SqlDataAdapter(query, constr); DataTable table = new DataTable(); da.Fill(table); GridView1.DataSource = table; GridView1.DataBind(); } protected void BindGridView() { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); if (DropDownList1.SelectedItem.Text == "Price: High To Low") { cmd = new SqlCommand("Select * From DetailsTable where type='Accounting' and city='Ahmedabad' order by price desc", con); } else if (DropDownList1.SelectedItem.Text == "Price: Low To High") { cmd = new SqlCommand("select * from DetailsTable where type='Accounting' and city='Ahmedabad' order by price asc", con); } else if (DropDownList1.SelectedItem.Text == "Most Recently Ads") { cmd = new SqlCommand("select * from DetailsTable where type='Accounting' and city='Ahmedabad' order by id desc", con); } SqlDataAdapter adap = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); adap.Fill(ds); GridView1.DataSource = ds; GridView1.DataBind(); } private void ddd() { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); if (ddlCity.SelectedItem.Text == "Bangalore") { cmd = new SqlCommand("select * from DetailsTable where type='Accounting' and city='Bangalore' order by price desc", con); } else if (ddlCity.SelectedItem.Text == "Chandigarh") { cmd = new SqlCommand("Select * From DetailsTable where type='Accounting' and State='Chandigarh' order by price desc", con); } else if (ddlCity.SelectedItem.Text == "all cities") { cmd = new SqlCommand("Select * From DetailsTable where type='Accounting' order by price desc", con); } SqlDataAdapter adap = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); adap.Fill(ds); GridView1.DataSource = ds; GridView1.DataBind(); } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { BindGridView(); } protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; BindGridView(); ddd(); } protected void ddlCity_SelectedIndexChanged1(object sender, EventArgs e) { ddd(); } } }
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; // BindGridView(); LoadData(); ddd(); }
protected void gridview_PageIndexChanging(object sender, GridViewPageEventArgs e) { urGridviewname.PageIndex = e.NewPageIndex; obj.gridview(gridviewname);//Connect gridview with ur function }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)