使用asp.net为gridview控件设置的页码? [英] page numbers set for gridview control using asp.net?

查看:103
本文介绍了使用asp.net为gridview控件设置的页码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,



使用asp.net设置的页码?



这里下面的代码一次不正常意味着:这里页面包含3并选择1和2正常但第3页未到来



这里有什么错误和任何修改请回复我


代码:

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();
    }
}
}

推荐答案

调用LoadData()而不是BindGridview()检查它工作与否



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

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
//        BindGridView();
          LoadData();
        ddd();
    }


Ste p 1:转到gridview属性,然后单击允许分页属性等于true。

例如:AllowPaging = True

第2步:将PageSize属性设置为5或10等(这是你的意愿)。



步骤3:转到gridview属性中的事件区域然后单击选择索引更改并双击该事件编写以下代码。




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.


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


}


这篇关于使用asp.net为gridview控件设置的页码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆