我正在尝试GridView
使用手动分页来实现。我想添加一个query string param
分页。这完全是为了SEO
,它是absolutely required
。该代码已在网站上发布,大约有 500 个条目(在 中的帖子gridview
)。
现在公司希望我做一个查询字符串参数,以便搜索引擎可以浏览所有页面并捕获它。现在搜索引擎只看到gridview 上的第1 页。这就是我从 SEO 团队了解到的。
我真的不知道如何做到这一点。请帮忙。我不能真正更改所有代码,因为它会弄乱所有已经上线的页面。
网格查看代码
<asp:GridView runat="server" AllowPaging="true" ID="entriesGridView" AutoGenerateColumns="false"
DataKeyNames="EntryId" ShowHeader="False" OnRowDataBound="entriesGridView_RowDataBound"
CssClass="grid" OnPageIndexChanging="entriesGridView_PageIndexChanging" PageSize="20">
<PagerStyle CssClass="pager"></PagerStyle>
<Columns>
// some template / bound fields
</Columns>
<EmptyDataTemplate>
// empty results text....
</EmptyDataTemplate>
<EmptyDataRowStyle HorizontalAlign="Center" />
</asp:GridView>
代码隐藏
protected void entriesGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
LoadEntriesGridView(false, false, false, sqlCriteria);
entriesGridView.PageIndex = e.NewPageIndex;
entriesGridView.DataBind();
}
数据源
public static EntryCollection LoadForCriteriaWithJoin(string sqlCriteria, bool isEmailQuery, bool isFullNameQuery, string sortExpression)
{
//DEFAULT SORT EXPRESSION
if (string.IsNullOrEmpty(sortExpression)) sortExpression = "OrderBy";
//CREATE THE DYNAMIC SQL TO LOAD OBJECT
var selectQuery = new StringBuilder();
selectQuery.Append("SELECT");
selectQuery.Append(" CE.* ");
selectQuery.Append("FROM EntryTable CE ");
selectQuery.Append("JOIN ContestantsTable CC ");
selectQuery.Append("ON CE.ContestantId = CC.ContestantId ");
string whereClause = null;
if (isEmailQuery)
whereClause = "WHERE CE.IsApproved = 1 AND CC.Email = @EmailAddress";
else if (isFullNameQuery)
whereClause = "WHERE CE.IsApproved = 1 AND CC.FirstName + ' ' + CC.LastName LIKE '%' + @FullName + '%'" +
"OR CE.CName LIKE '%' + @FullName + '%'" +
"OR CE.CTitle LIKE '%' + @FullName + '%'" +
"OR CE.Answer1 + ' ' + CE.Answer2 + ' ' + Answer3 LIKE '%' + @FullName + '%'";
else
whereClause = "WHERE CE.IsApproved = 2"; // returning Empty result...
if (!String.IsNullOrEmpty(sqlCriteria))
selectQuery.Append(whereClause);
selectQuery.Append(" ORDER BY " + sortExpression);
var database = T.I.Database;
var selectCommand = database.GetSqlStringCommand(selectQuery.ToString());
if (isEmailQuery)
database.AddInParameter(selectCommand, "@Email", System.Data.DbType.String, sqlCriteria);
if (isFullNameQuery)
database.AddInParameter(selectCommand, "@FullName", System.Data.DbType.String, sqlCriteria);
//EXECUTE THE COMMAND
var results = new EntryCollection();
using (var dr = database.ExecuteReader(selectCommand))
{
while (dr.Read())
{
var entry = new Entry();
MWCompetitionsEntry.LoadDataReader(entry, dr);
results.Add(entry);
}
dr.Close();
}
return results;
}