对不起有些暧昧的头衔。我会尽力详细解释。
因此,我正在使用正面的<a href>
标记List.aspx
代码部分如下所示。
<%
for (int x = 1; x < page_count + 1; x++)
{
%>
<a name="page_index" href="List.aspx?page=<%=x %>"><%=x %></a>
<% } %>
因此,通过使用GET
方法,我将页面信息移至背面List.aspx.cs
,此处使用查询语句,从MSSQL DB
page_number = Request.QueryString["page"];
int_page_number = Convert.ToInt32(page_number);
string sql = ""; //sql query
CDatabase _db = new CDatabase();
sql = "SELECT * FROM (SELECT ROW_NUMBER() OVER (ORDER BY ArticleIdx) AS orderednumber,";
string tail = "ArticleIdx, writerName, passwords, title, content, writeDate From dbo.article) AS ordering WHERE orderednumber BETWEEN " +(10*(int_page_number-1)+1).ToString() + " AND " + (10*int_page_number).ToString();
sql = sql + tail;
然而,问题是因为我设置为默认页面List.aspx
如果我只是通过我的本地服务器进入,在List.aspx页面中我的主板上没有任何内容。如果我点击下面的数字1 href tag
,则会移至List.aspx?page=1
并显示10个内容。
如何将默认List.aspx
页面连接到page = 1?
答案 0 :(得分:1)
只检查查询字符串是否存在,如果不存在,请在其余代码运行之前将页码设置为1
If (Request.QueryString["page"] == "") {
page_number = 1;
}
else {
page_number = Request.QueryString["page"];
}
编辑: 如果你愿意,甚至可以这样做
page_number = Request.QueryString["page"];
if (page_number == "") page_number = 1
答案 1 :(得分:1)
超越
//Set a default
int int_page_number = 1;
//Check there is a value in the query string for page
if(!String.IsNullOrEmpty(Request.QueryString["page"]))
{
//Try to parse the query string value to an integer
if(! int.TryParse(Request.QueryString["page"] , out int_page_number))
{
//Revert back to 1 if it fails
int_page_number = 1;
}
}
这也可确保页码为数字。