Response.Redirect页面传值问题

言月秋 2015-07-08 02:11:02
<asp:GridView ID="GridView1" runat="server" Visible="False" OnRowEditing="GridView_RowEditing" onselectedindexchanged="GridView1_SelectedIndexChanged">
<Columns>
<asp:ButtonField CommandName="Edit" Text="详细" />
</Columns>
</asp:GridView>
gridview中绑定了 protected void GridView_RowEditing(object sender, GridViewEditEventArgs e)
{
this.GridView1.EditIndex = e.NewEditIndex;
int selectIndex = this.GridView1.EditIndex;
string louhao = this.GridView1.Rows[selectIndex].Cells[1].Text.ToString();
string qinshihao = this.GridView1.Rows[selectIndex].Cells[2].Text.ToString();
base.Response.Redirect("detailed.aspx?louhao =" + louhao + "&qinshihao=" + qinshihao + " " );

}
detailed.aspx中
string louhao = Server.UrlDecode(Request["louhao"]);
string qinshihao = Server.UrlDecode(Request["qinshihao"]);
Response.Write("<script>alert('" + louhao + "')</script>");
Response.Write("<script>alert('" + qinshihao + "')</script>");


if (!louhao.Trim().Equals("")) 这里报错未将对象引用设置到对象的实例。
{
louhao = " and louhao='" + louhao + "'";
}
else
{
louhao = "";
}
估计报错原因为未接受到上个页面传过来的值,所以判断时报错,大家看下我传值哪里写错了。
...全文
305 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
fantasy5252 2015-07-09
  • 打赏
  • 举报
回复
受教了我也出现过
言月秋 2015-07-09
  • 打赏
  • 举报
回复
谢谢大家,已经解决了。
litengfei0020 2015-07-09
  • 打赏
  • 举报
回复
打个断点 看下具体传过来的值是什么!
insus 2015-07-09
  • 打赏
  • 举报
回复
实现Redirect在RowEditing事件不可以。 此事件只是是否允许GridView切换至编辑关状态。 在OnRowDataBound事件中写。
言月秋 2015-07-08
  • 打赏
  • 举报
回复
引用 2 楼 Z65443344 的回复:
louhao.Trim().Equals("")报错 那么如果louhao不是null,louhao.Trim()的返回值也会是字符串,而不会是null 那么基本可以断定就是louhao=null 那么你应该断点跟,看string louhao = Server.UrlDecode(Request["louhao"]);这个过程到底到哪一步是null 是Request["louhao"]就是null,还是Server.UrlDecode的返回值变成了null
谢谢你的意见,仔细调试发现 string louhao = this.GridView1.Rows[selectIndex].Cells[1].Text.ToString();,这里的时候就已经没有值了。正在想办法解决中。
於黾 2015-07-08
  • 打赏
  • 举报
回复
base.Response.Redirect("detailed.aspx?louhao =" + louhao + "&qinshihao=" + qinshihao + " " ); 这里你传参数的时候, string louhao = this.GridView1.Rows[selectIndex].Cells[1].Text.ToString(); 这个是数据库里的字符串,它本身应该没有被编码的 那么你获取到参数之后,为啥要执行Server.UrlDecode解码??
於黾 2015-07-08
  • 打赏
  • 举报
回复
louhao.Trim().Equals("")报错 那么如果louhao不是null,louhao.Trim()的返回值也会是字符串,而不会是null 那么基本可以断定就是louhao=null 那么你应该断点跟,看string louhao = Server.UrlDecode(Request["louhao"]);这个过程到底到哪一步是null 是Request["louhao"]就是null,还是Server.UrlDecode的返回值变成了null
於黾 2015-07-08
  • 打赏
  • 举报
回复
未将对象引用设置到对象的实例 说明有对象是null了 你需要先断点调试看到底哪个对象是null,再具体找原因 不要靠猜

62,074

社区成员

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

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

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

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