C# 使用带分页的中继器进行排序
我有一个中继器,我正在使用分页。它是有效的,但它在我的分类中做了一些有趣的事情。首先,如果我按下排序按钮,我的分页控件会显示两次。其次,它根据默认排序顺序分页。你知道哪里不对吗C# 使用带分页的中继器进行排序,c#,asp.net,pagination,repeater,code-behind,C#,Asp.net,Pagination,Repeater,Code Behind,我有一个中继器,我正在使用分页。它是有效的,但它在我的分类中做了一些有趣的事情。首先,如果我按下排序按钮,我的分页控件会显示两次。其次,它根据默认排序顺序分页。你知道哪里不对吗 protected void btnSort_Click(object sender, EventArgs e) { Show_Data(); } public void Show_Data() { SqlConnection con = new
protected void btnSort_Click(object sender, EventArgs e)
{
Show_Data();
}
public void Show_Data()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["PBRConnectionString"].ConnectionString);
string srtOrder = cboSortBy.Text;
SqlDataAdapter adp = new SqlDataAdapter("select [ACCT_LIST].*, [ACCT_GRP_LIST].ACCT_GRP from [ACCT_LIST] LEFT JOIN [ACCT_GRP_LIST] on [ACCT_GRP_LIST].ACCT_GRP_PK = [ACCT_LIST].ACCT_GRP_FK ORDER BY " + srtOrder + "", con);
DataSet ds = new DataSet();
adp.Fill(ds, "TAcctList");
//Pagination code so only a set number of records loads at a time.
// Done to speed up the loading, since this list gets really long.
PagedDataSource pds = new PagedDataSource();
pds.DataSource = ds.Tables["TAcctList"].DefaultView;
pds.AllowPaging = true;
pds.PageSize = 20;
int currentPage;
if (Request.QueryString["page"] != null)
{
currentPage = Int32.Parse(Request.QueryString["page"]);
}
else
{
currentPage = 1;
}
pds.CurrentPageIndex = currentPage - 1;
Label1.Text = "Page " + currentPage + " of " + pds.PageCount;
if (!pds.IsFirstPage)
{
MenuItem itemMessage = NavMenu.FindItem("First");
itemMessage.NavigateUrl = Request.CurrentExecutionFilePath + "?page=1";
}
AcctRepeater.DataSource = pds;
AcctRepeater.DataBind();
CreatePagingControl(pds.PageCount, pds.CurrentPageIndex);
// End of Pagination code
con.Close();
}
在ASP.Net端,按钮控件如下所示:
<table>
<tr>
<td width="150"><asp:DropDownList ID="cboSortBy" runat="server" Width="120">
<asp:ListItem Value="StatusText">Benefit Type</asp:ListItem>
<asp:ListItem Value="PRIORITY_RANK">Priority Rank</asp:ListItem>
<asp:ListItem Value="ACTIVE_FLG">Active Flag</asp:ListItem>
</asp:DropDownList></td>
<td width="180"><asp:Button ID="btnSort" runat="server"
Text="Sort" Width="121px" onclick="btnSort_Click" /></td>
</tr>
</table>
福利类型
优先级
活动标志
分页部分是新的,但在添加它之前,排序功能工作得很好。现在,分页部分工作正常,但排序部分出现问题。我想不出分页部分的哪个部分把它弄得乱七八糟。试试看
ds.Tables["TAcctList"].DefaultView.Sort = "PRIORITY_RANK ASC";
我想控件出现两次是因为我没有回发?不过,我不确定排序问题。好的,我认为部分问题在于表单正在发回,并且保存排序值的组合框被重置为默认值。我的分页创建的链接类似:。所以,我猜当你点击时,它会进行一次完整的回发,这会重置排序组合。有人知道如何应对吗?我想我需要以某种方式将组合选择的值向前推进。关键是,它会回到默认值。硬编码排序顺序对我没有帮助,我需要让它在刷新时识别排序顺序。不要硬编码。从下拉列表中获取它。我想我没必要说得那么具体。很抱歉关键是,按上述方式设置。