Click here to Skip to main content
15,894,896 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

page numbers set using asp.net?

here below code once not working properly means : here pages contain 3 and select 1 and 2 coming properly but 3rd page is not coming

here what mistake and any modification please reply me

code:
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();
    }
}
}
Posted
Updated 22-Sep-14 18:54pm
v4

Call LoadData() instead of BindGridview() check it is working or not

C#
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
//        BindGridView();
          LoadData();
        ddd();
    }
 
Share this answer
 
Step 1 : go to gridview property then click Allow paging property equal to true.
Eg : AllowPaging = True
Step 2 : Put the PageSize property as 5 or 10 etc (Thats ur wish).

Step 3 : Go to event area in gridview property then click select index changing and doubl click the event write the below code.


C#
protected void gridview_PageIndexChanging(object sender, GridViewPageEventArgs e)
   {
       urGridviewname.PageIndex = e.NewPageIndex;
       obj.gridview(gridviewname);//Connect gridview with ur function


}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900