注册 登录
编程论坛 ASP.NET技术论坛

GridView改变显示条件后如何重新绑定分页函数

weboss8 发布于 2008-07-17 11:51, 2119 次点击



上面3个图是我要解释的,我刚学net很多东西搞不清楚,请大家帮一下
默认打开这个页面时,显示的是第一个图,绑定分页,
然后通过dropdownlist改变这个页面显示的内容,然后再绑定分页就迷糊了,出现了第三种情况
就是点击分页后,绑定了默认的情况而不是我选择的条件,代码如下:
public partial class _Admin_Order_Form_List : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            bandpage();
        }
    }
    private void bandpage()
    {
        SqlConnection con = Dataconn.createconn();
        con.Open();
        SqlDataAdapter sda = new SqlDataAdapter("select * from Order_Form", con);
        DataSet ds = new DataSet();
        //将数据填充到Dataset数据集中
        sda.Fill(ds);
        this.OrderList.DataSource = ds;
        this.OrderList.DataBind();
        con.Close();
    }
    protected void OrderList_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.OrderList.PageIndex = e.NewPageIndex;
        bandpage();
    }

    protected void Ddl_SelectedIndexChanged(object sender, EventArgs e)
    {
        int sid = int.Parse(this.Ddl.SelectedValue.ToString());
        SqlConnection con = Dataconn.createconn();
        con.Open();
        if (sid == 0)
        {
            SqlDataAdapter sda = new SqlDataAdapter("select * from Order_Form", con);
            DataSet ds = new DataSet();
            //将数据填充到Dataset数据集中
            sda.Fill(ds);
            this.OrderList.DataSource = ds;
            this.OrderList.DataBind();
            con.Close();
        }
        else
        {
            SqlDataAdapter sda = new SqlDataAdapter("select * from Order_Form where Order_Lc=" + sid, con);
            DataSet ds = new DataSet();
            //将数据填充到Dataset数据集中
            sda.Fill(ds);
            this.OrderList.DataSource = ds;
            this.OrderList.DataBind();
            con.Close();
        }

    }
}
主要还是不知道换了条件后该如何再次使用OrderList_PageIndexChanging
5 回复
#2
weboss82008-07-18 08:10
人呢?
#3
hnczljt2008-07-18 23:35
你那又多少条数据,建议你查询的的时候控制要显示的内容
#4
冰彩虹2008-07-18 23:57
你把以下这段代码放到bandpage()里才对呀

int sid = int.Parse(this.Ddl.SelectedValue.ToString());
        SqlConnection con = Dataconn.createconn();
        con.Open();
        if (sid == 0)
        {
            SqlDataAdapter sda = new SqlDataAdapter("select * from Order_Form", con);
            DataSet ds = new DataSet();
            //将数据填充到Dataset数据集中
            sda.Fill(ds);
            this.OrderList.DataSource = ds;
            this.OrderList.DataBind();
            con.Close();
        }
        else
        {
            SqlDataAdapter sda = new SqlDataAdapter("select * from Order_Form where Order_Lc=" + sid, con);
            DataSet ds = new DataSet();
            //将数据填充到Dataset数据集中
            sda.Fill(ds);
            this.OrderList.DataSource = ds;
            this.OrderList.DataBind();
            con.Close();
        }
#5
寂寞的刺猬2008-07-19 00:31
分页函数不需要重新写的。
http://wlb.wlb.blog.
#6
雪雨星风2008-07-23 11:15
其实唯一在变的就是sql语句
你写一个带sql语句的绑定方法就搞定了
1