我有一个ListView
按钮DataPager
(1,2,3,...)中的分页不保留在上下文中是坏事的顺序parameters
(querystring
机器人SEO
认为它是重复的内容)。
IE 如果我的页面是:
Test.aspx?r=8&type=10
the pager buttons show:
Test.aspx?type=8&r=10&page=1
Test.aspx?type=8&r=10&page=2
等等...我认为控件按字母顺序排列它们?
我试图在控制PreRender()
事件上覆盖这些 URL,但它仍然呈现URL
如上所述的...
有人遇到过这个问题吗??
谢谢。
ASPX:
<asp:ListView ID="ListViewSearchResults" runat="server" GroupItemCount="3"
OnItemDataBound="ListViewSearchResults_ItemDataBound"
OnPagePropertiesChanging="ListViewSearchResults_PagePropertiesChanging" >
......
</asp:ListView>
......
<asp:DataPager ID="ListViewPager" runat="server" QueryStringField="page"
OnDataBinding="ListViewPager_DataBinding" OnPreRender="ListViewPager_PreRender"
PagedControlID="ListViewSearchResults" PageSize="21" >
<Fields>
<asp:NextPreviousPagerField ShowFirstPageButton="true"
ShowPreviousPageButton="false" ShowNextPageButton="false"
ShowLastPageButton="false" ButtonCssClass="pagingright1" ButtonType="Link"
FirstPageText="" />
<asp:NextPreviousPagerField ShowFirstPageButton="false"
ShowPreviousPageButton="true" ShowNextPageButton="false"
ShowLastPageButton="false" ButtonCssClass="pagingright2" ButtonType="Link"
PreviousPageText="" />
<asp:NumericPagerField ButtonType="Link" CurrentPageLabelCssClass="pagingcurrent" RenderNonBreakingSpacesBetweenControls="false" ButtonCount="10" />
<asp:NextPreviousPagerField ShowFirstPageButton="false" ShowPreviousPageButton="false" ShowNextPageButton="true" ShowLastPageButton="false" ButtonCssClass="pagingleft2" ButtonType="Link" NextPageText="" />
<asp:NextPreviousPagerField ShowFirstPageButton="false" ShowPreviousPageButton="false" ShowNextPageButton="false" ShowLastPageButton="true" ButtonCssClass="pagingleft1" ButtonType="Link" LastPageText="" />
</Fields>
</asp:DataPager>
CS:尝试以编程方式修复链接
private void FixAllPagerLinks(string FixedUrl)
{
foreach (Control c in ListViewPager.Controls)
{
if(c.HasControls())
{
if(c.Controls[0] is HyperLink)
{
string PageParam = string.Empty;
string CurrentUrl = ((HyperLink)c.Controls[0]).NavigateUrl;
char[] pageparam = new char[CurrentUrl.Length - CurrentUrl.IndexOf("page")];
CurrentUrl.CopyTo(CurrentUrl.IndexOf("page"), pageparam, 0, CurrentUrl.Length - CurrentUrl.IndexOf("page"));
PageParam = new string(pageparam);
((HyperLink)c.Controls[0]).NavigateUrl = string.Format("/{0}&{1}", FixedUrl , PageParam);
}
}
}
}
// in the DataPager PreRender Event nothing happen
//but on page prerender event it show the correct links but after
//clicking on next page in the pager it's messed up again
protected override void OnPreRender(EventArgs e)
{
//getting the URL
string NextPageurl = ((System.Web.UI.WebControls.HyperLink)
(ListViewPager.Controls[0].Controls[0])).NavigateUrl;
//removing the page=1 to get the Basic url of the link
NextPageurl = NextPageurl.Replace("&page=1", string.Empty).Replace("?page=1", string.Empty);
string FullFixedUrl = FixQueryStringParameters(NextPageurl );
FixAllPagerLinks(FullFixedUrl);
}
private string FixQueryStringParameters(string QueryWithParams)
{
string returnQueryStringParams = string.Empty;
string p1 = string.Empty;
string p2 = string.Empty;
string p3 = string.Empty;
Dictionary<string, string> QSKeyValuePairs = new Dictionary<string, string>();
if (QueryWithParams.Split('?').Length > 1)
{
string parameters = QueryWithParams.Split('?')[1];
if (parameters.Split('&').Length > 1)
{
p1 = parameters.Split('&')[0];
QSKeyValuePairs.Add(p1.Split('=')[0], p1.Split('=')[1]);
p2 = parameters.Split('&')[1];
QSKeyValuePairs.Add(p2.Split('=')[0], p2.Split('=')[1]);
if (parameters.Split('&').Length > 2)
{
p3 = parameters.Split('&')[2];
QSKeyValuePairs.Add(p3.Split('=')[0], p3.Split('=')[1]);
}
}
}