using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Data.SqlClient; public partial class MyorderList : System.Web.UI.Page { static int pageN = 0; static PagedDataSource pds = new PagedDataSource();//静态变量只初始化一次 string sqlstr; static string UserName; protected void Page_Load(object sender, EventArgs e) { try { System.Data.DataTable dt = (DataTable)Session["member"]; UserName = dt.Rows[0]["cid"].ToString(); } catch { Response.Redirect("default.aspx"); } if (!IsPostBack) { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString); // string sqlstr = "select top (" + pagecount + ") * from MyuserTb where ID not in (select top (" + pagec =-ount * (pageN - 1) + ") id from MyuserTb)"; string sqlstr = "select (tab2.amount*(select vip_price_rmb from v3_merchandises where pid = tab2.pid)) as price,(select trade_name_cn from v3_merchandises where pid = tab2.pid) as BookName,* from v3_order as tab1 inner join v3_order_item as tab2 on tab1.oid = tab2.oid and tab2.cid = tab1.cid inner join v3_pic_path as pic on tab2.pid = pic.pid where tab1.cid = '" + UserName + "' and pic.show =1"; SqlDataAdapter sda = new SqlDataAdapter(sqlstr, con); //数据桥接器 作用是把数据读出来 不用执行 一次性读完备用,读完数据库关闭 。 sqldatareader是一条一条的读数据,数据库总是再打开状态 DataTable dt = new DataTable();// 作为临时保存数据的虚拟表 作为数据源 sda.Fill(dt);// 把桥接器里面读出来的数据 放在虚拟表里面 pds.DataSource = dt.DefaultView;//把dataable的值 赋给 pds Bind(0); } } private void Bind(int pageN) { pds.AllowPaging = true; // 是否分页 pds.PageSize = 10; //页面大小 pds.CurrentPageIndex = pageN;// 获取当前页面, 让下面的 显示当前页面 Repeater1.DataSource = pds; Repeater1.DataBind(); } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { sqlstr = "select (tab2.amount*(select vip_price_rmb from v3_merchandises where pid = tab2.pid)) as price,(select trade_name_cn from v3_merchandises where pid = tab2.pid) as BookName,* from v3_order as tab1 inner join v3_order_item as tab2 on tab1.oid = tab2.oid and tab2.cid = tab1.cid inner join v3_pic_path as pic on tab2.pid = pic.pid where tab1.cid = '" + UserName + "' and pic.show =1 "; if (DropDownList1.SelectedIndex == 1) { sqlstr += " and datediff(month,tab2.addtime,getdate())=0 "; } else if (DropDownList1.SelectedIndex == 2) { sqlstr += " and datediff(month,tab2.addtime,getdate())!=0 "; } if (DropDownList2.SelectedIndex == 1) { sqlstr += " and isend =1"; } else if (DropDownList2.SelectedIndex == 2) { sqlstr += " and isend =0"; } sqlstr += " order by tab2.addtime"; pds.DataSource = new common().ExcuteReader(sqlstr).Tables[0].DefaultView; pds.AllowPaging = true; // 是否分页 pds.PageSize = 10; //页面大小 pageN = 0; pds.CurrentPageIndex = pageN;// 获取当前页面, 让下面的 显示当前页面 Repeater1.DataSource = pds; Repeater1.DataBind(); } protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e) { sqlstr = "select (tab2.amount*(select vip_price_rmb from v3_merchandises where pid = tab2.pid)) as price,(select trade_name_cn from v3_merchandises where pid = tab2.pid) as BookName,* from v3_order as tab1 inner join v3_order_item as tab2 on tab1.oid = tab2.oid and tab2.cid = tab1.cid inner join v3_pic_path as pic on tab2.pid = pic.pid where tab1.cid = '" + UserName + "' and pic.show =1 "; if (DropDownList1.SelectedIndex == 1) { sqlstr += " and datediff(month,tab2.addtime,getdate())=0 "; } else if (DropDownList1.SelectedIndex == 2) { sqlstr += " and datediff(month,tab2.addtime,getdate())!=0 "; } if (DropDownList2.SelectedIndex == 1) { sqlstr += " and isend =1"; } else if (DropDownList2.SelectedIndex == 2) { sqlstr += " and isend =0"; } sqlstr += " order by tab2.addtime"; pds.DataSource = new common().ExcuteReader(sqlstr).Tables[0].DefaultView; pds.AllowPaging = true; // 是否分页 pageN = 0; pds.PageSize = 10; //页面大小 pds.CurrentPageIndex = pageN;// 获取当前页面, 让下面的 显示当前页面 Repeater1.DataSource = pds; Repeater1.DataBind(); } protected void lblup_Click(object sender, EventArgs e) { if (pageN > 0) pageN--; Bind(pageN); } protected void lbldown_Click(object sender, EventArgs e) { if (pageN < pds.PageCount - 1) pageN++; Bind(pageN); } }