QueryString传递变量的问题,给位大虾帮帮忙啊~~~
下面是手动绑定DetailsView的数据源的代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DetailsViewBind();
}
}
SqlDataSource ss = new SqlDataSource();
private void DetailsViewBind()
{
ss.ConnectionString = ConfigurationManager.ConnectionStrings["MyWebConnectionString"].ToString();
String name1 = Request.QueryString["name"];//调试中查看页面变量已经传递过来了,与name2一致
string name2 = "玉米疯顶病";
MessageBox.Show (name1, "信息", MessageBoxButtons.OK );
ss.SelectCommand = "SELECT * FROM [DiseaseDetails] WHERE ([DiseaseName]= '"+name1+"')";//这里如果用name2就能够显示数据,为什么name1不行?
ss.Select (DataSourceSelectArguments.Empty);
DetailsView1.DataSource = ss;
DetailsView1.DataBind();
//string name = Request.QueryString["name"].ToString();
}
想了好久也没弄明白,大家帮帮忙啊!!!!
------解决方案--------------------
QueryString要进行Server.UrlEncode("玉米")才能传
也就是浏览器地址栏中需要%E7%8E%89%E7%B1%B3
------解决方案--------------------你先把name1 Response.Write(name1 )出来看是不是乱码
web.config里面的编码要写utf-8,不要写其他的