我正在尝试使用手动分页来实现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;
}