参照网上做了repeater 排序,但是当前页的排序,如果要对全部数据怎么排序啊?
我用的da.Fill(ds,AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, table);
这个方法,但是如果da.Fill(ds) 这一个参数的话,就是所有的数据绑定到页面,菜鸟求助
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);
}
}
我用的da.Fill(ds,AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, table);
这个方法,但是如果da.Fill(ds) 这一个参数的话,就是所有的数据绑定到页面,菜鸟求助
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);
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货