分页 传值为空!崩溃中。。。

cctvkmna 2011-10-18 09:31:04
a页面是个搜索框 传中文或英文。

js控制:


function gjz()
{
var sk = document.getElementById('txtInfo').value;

window.location.href = "ShowKeyWord.aspx?txtNameBook='" + encodeURIComponent (sk) +"'&page=1";

}



ShowKeyWord.aspx页面



protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
int pageIndex = 1; //显示第一条记录

int pageSize = 2; //每页显示几条记录

int PageItem = 5;

int toatalCountRecord = 0;

if (Request.QueryString["page"] == null)
{
pageIndex = 1;
}
else
{
pageIndex = Int32.Parse(Request.QueryString["page"]);
}



string txtNameBook = Request.QueryString["txtNameBook"].ToString();

DataSet ds = this.GetPage(pageIndex, pageSize, txtNameBook, out toatalCountRecord);

Repeater1.DataSource = ds;

Repeater1.DataBind();



//string strWhere = "txtNameBook=" + System.Web.HttpUtility.UrlEncode(nbk.ToString(),Encoding.Default);

string strWhere = "txtNameBook=" + txtNameBook.ToString();

this.BuildPages(toatalCountRecord, pageSize, pageIndex, PageInfo, strWhere);

}
}





public void BuildPages(int ToatalCountRecord, int PageItem, int CurrentPage, HtmlGenericControl PageInfo, string strWhere) {
int Step = 5;//偏移量
int LeftNum = 0;//左界限
int RightNum = 0;//右界限
string PageUrl = HttpContext.Current.Request.FilePath;
int PageCount = (int)Math.Ceiling((double)(ToatalCountRecord) / PageItem);
if (CurrentPage - Step < 1)
{
LeftNum = 1;
}
else
{
LeftNum = CurrentPage - Step;
}
if (CurrentPage + Step > PageCount)
{
RightNum = PageCount;
}
else
{
RightNum = CurrentPage + Step;
}
string OutPut = "";
if (strWhere != null)
strWhere = "&" + strWhere;
OutPut += "<a href='" + PageUrl + "?page=1" + strWhere + "' mce_href='" + PageUrl + "?page=1" + strWhere + "'>" + "首页" + "</a>";
if (CurrentPage > 1)
{
OutPut += " <a href='" + PageUrl + "?page=" + (CurrentPage - 1) + strWhere + "' mce_href='" + PageUrl + "?page=" + (CurrentPage - 1) + strWhere + "'>" + "上一页" + " </a>";
}
if (CurrentPage == 1)
{
OutPut += " 上一页 ";
}
for (int i = LeftNum; i <= RightNum; i++)
{
if (i == CurrentPage)
{
OutPut += " " + "[" + i.ToString() + "]" + "";
}
else
{
OutPut += " <a href='" + PageUrl + "?page=" + i.ToString() + strWhere + "' mce_href='" + PageUrl + "?page=" + i.ToString() + strWhere + "'>" + " " + "[" + i.ToString() + "]" + " " + " </a>";
}
}
if (CurrentPage < PageCount)
{
OutPut += " <a href='" + PageUrl + "?page=" + (CurrentPage + 1) + strWhere + "' mce_href='" + PageUrl + "?page=" + (CurrentPage + 1) + strWhere + "'>" + "下一页" + " </a>";
}
if (CurrentPage == PageCount)
{
OutPut += " 下一页 ";
}
int last;
if (ToatalCountRecord % PageItem == 0)
last = ToatalCountRecord / PageItem;
else
last = ToatalCountRecord / PageItem + 1;
OutPut += "<a href='" + PageUrl + "?page=" + last + strWhere + "' mce_href='" + PageUrl + "?page=" + last + strWhere + "'>" + "末页" + "</a>";
PageInfo.InnerHtml = OutPut;
}




用调试测试 OutPut 第一次加载时候返回的是:

OutPut = "<a href='/Cw/cww/ShowKeyWord.aspx?page=1&txtNameBook='老公'' mce_href='/Cw/cww/ShowKeyWord.aspx?page=1&txtNameBook='老公''>首页</a> 上一页 [1] <a href='/Cw/cww/ShowKeyWord.aspx?page=2&txtNameBook='老公'' mce_href='/Cw/cww/ShowKeyWord.aspx?page=2&txtNameBook='老公''> [2]</a>

txtNameBook明明有值的,可页面移到 分页 [2] txtNameBook= (什么也没有!)
...全文
127 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
极地_雪狼 2011-10-18
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 net_lover 的回复:]
window.location.href = "ShowKeyWord.aspx?txtNameBook=" + encodeURIComponent (sk) +"&page=1";
去掉单引号
[/Quote]
+1
孟子E章 2011-10-18
  • 打赏
  • 举报
回复
string strWhere = "txtNameBook=" + Server.UrlEncode(txtNameBook.ToString());

孟子E章 2011-10-18
  • 打赏
  • 举报
回复
window.location.href = "ShowKeyWord.aspx?txtNameBook=" + encodeURIComponent (sk) +"&page=1";
去掉单引号

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧