100问个排序,查询分页的问题,帮顶有分!
1,我的datagrid绑定了数据库有6页,查询的时候重新绑定有3页,但按第二页的时候,我的datagrid又变成6页.也就是又重新绑定了!郁闷中!
2,我做了点列头排序的功能,但只能按desc或asc排序,网上很多都是可以在desc/asc之间互换的呀!怎么样实现这种功能!还有排序后按下一页也是重新绑定了..
请高手手多帮忙!
[解决办法]
LZ的意思是说1页升序,一页降序,是吗?
[解决办法]
用ViewState存放排序状态
[解决办法]
幫頂
[解决办法]
你把代碼貼出來,才好幫你分析呀。
[解决办法]
因为你页面绑定的数据
与你查询绑定得到的数据不一致
你只需要第一次时候绑定页面数据(绑定一次)
以后的都绑定到查询数据(绑定多次)
[解决办法]
我一看是VB.NET的代码就没力气了..
[解决办法]
bangding
[解决办法]
VB啊。。。。。
[解决办法]
jf
[解决办法]
Dim dv As DataView = New DataView
dv = ds.Tables( "fileinfo ").DefaultView
dv.Sort = SortField
MyDataGrid.DataSource = ds.Tables( "fileinfo ").DefaultView
MyDataGrid.DataBind()
ShowStats()
[解决办法]
上面发错了。。。
Dim dv As DataView = New DataView
dv = ds.Tables( "fileinfo ").DefaultView
dv.Sort = SortField
MyDataGrid.DataSource = dv
MyDataGrid.DataBind()
ShowStats()
试试这样
[解决办法]
有个方法 SortExpression
[解决办法]
我用Session存放条件的,就没事下一页也没有问题
[解决办法]
//这个实现了简单的功能,将就看看
http://community.csdn.net/Expert/topic/5537/5537248.xml?temp=.9052851
<ASP:DataGrid id= "DataGrid1 " runat= "server " AllowSorting= "True " AutoGenerateColumns= "False ">
<Columns>
<asp:BoundColumn DataField= "au_id " SortExpression= "au_id " HeaderText= "au_id "> </asp:BoundColumn>
<asp:BoundColumn DataField= "au_lname " SortExpression= "au_lname " HeaderText= "au_lname "> </asp:BoundColumn>
<asp:BoundColumn DataField= "au_fname " SortExpression= "au_fname " HeaderText= "au_fname "> </asp:BoundColumn>
</Columns>
</ASP:DataGrid>
//aspx.cs
private void BindGrid()
{
SqlConnection cn = new SqlConnection( "server=.;uid=sa;pwd=sa;database=pubs ");
SqlDataAdapter da = new SqlDataAdapter( "select au_id, au_lname, au_fname from authors ", cn);
DataSet ds = new DataSet();
cn.Open();
da.Fill(ds);
cn.Close();
DataGrid1.DataSource = ds;
DataGrid1.DataKeyField = "au_id ";
DataGrid1.DataBind();
}
private void BindGrid(string str)
{
SqlConnection cn = new SqlConnection( "server=.;uid=sa;pwd=sa;database=pubs ");
SqlDataAdapter da = new SqlDataAdapter( "select au_id, au_lname, au_fname from authors order by " + str + " " + ViewState[ "Direction "].ToString() , cn);
DataSet ds = new DataSet();
cn.Open();
da.Fill(ds);
cn.Close();
DataGrid1.DataSource = ds;
DataGrid1.DataKeyField = "au_id ";
DataGrid1.DataBind();
}
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
ViewState[ "Direction "] = "ASC ";
BindGrid();
}
}
private void DataGrid1_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
if (ViewState[ "Direction "].ToString() == "ASC ")
ViewState[ "Direction "] = "DESC ";
else
ViewState[ "Direction "] = "ASC ";
BindGrid(e.SortExpression);
}