日期:2014-05-18 浏览次数:20497 次
function Getsort(obj) { // document.all.sortfield.value=obj; document.getElementById("sortfield").value=obj; if(document.getElementById("sortstring").value=='ASC') { document.getElementById("sortstring").value='DESC'; } else if(document.getElementById("sortstring").value=='DESC') { document.getElementById("sortstring").value='ASC'; } __doPostBack('LinkButton1',''); }
后台代码: public DataSet GetSoftTj(AspNetPager AspNetPager1, string condition) { SqlConnection conn = db.CreateConnection(); string sql = @"select a.Title,COUNT(a.Title) as shu from Product a,ProductComputer b, Computer c where a.Product_Idn=b.Product_Idn and b.Computer_Idn=c.Computer_Idn and a.title like N'%"+condition +"%' group by Title"; SqlDataAdapter da = new SqlDataAdapter(sql,conn); DataSet ds = new DataSet(); try { da.Fill(ds,AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "table2"); } catch (SqlException ex) { throw new Exception(ex.Message, ex); } return ds; } private void Bind(string str) { if (Request.Cookies["text1"] != null) { DataSet ds = bl.GetSoftTj(AspNetPager1,Request.Cookies["text1"].Value.ToString()); DataView dv = ds.Tables[0].DefaultView; dv.Sort = str; Repeater1.DataSource = dv; Repeater1.DataBind(); } else { } } private void BindAspNetPager() { if (Request.Cookies["text1"] != null) { AspNetPager1.RecordCount = bl.SoftCountTj(Request.Cookies["text1"].Value.ToString()); } else { } } protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e) { AspNetPager1.CurrentPageIndex = e.NewPageIndex; Bind(""); } protected void LinkButton1_Click(object sender, EventArgs e) { string sortfield1 = sortfield.Value; string sortstring1 = sortstring.Value; string a = sortfield1 + " " + sortstring1; if (a != "" && a != null) { Bind(a); } }