如何将查询字符串从母版页菜单控件传递到内容页面 [英] How to Pass query String from master page menu control to content page
问题描述
hai,
我是asp.net的新手并且一直在购物车项目中工作。现在问题是我有两个表一个是菜单(menuid(primarykey),menuname)和另一个表产品(价格,menuid(fk),productname,...)和主页menu控件中的菜单控件有男人,连衣裙,衬衫等子菜单
裤子
T -shirts
当我点击Shirts它应该只在查看Products.aspx页面中显示男士衬衫,通过获取查询字符串[menu id]中的值,我在视图Products.aspx
hai,
I'm new to asp.net and been working in the shopping cart project .Now the problem is i have two table one is menu(menuid(primarykey),menuname)and another table products(price,menuid(fk),productname,...)and menu control in master page menucontrol have submenus like men,Dresses,Shirts
Pants
T-shirts
when i click Shirts it should only display the men's Shirts in view Products.aspx page by taking values in query string[menu id]and i have used this code in view Products.aspx
private void BindGridData()
{
con.Open();
int menuid = int.Parse(Request.QueryString["MenuId"]);
string sql = "select * from rsa_ProductItemTable where MenuId='" + menuid + "'";
SqlDataAdapter da = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
da.Fill(ds);
DataList1.DataSource = ds;
DataList1.DataBind();
con.Close();
}
错误是值不能为空。
参数名称:字符串
请帮帮我有了这个,我必须在菜单点击事件中添加任何想法。我的问题是如何从主页面传递查询字符串以及如何在视图Products.aspx页面中获取它应该根据菜单ID显示结果。
提前致谢
error is Value cannot be null.
Parameter name: String
Please Help me with this do i have to add any think in menu click event.My question is how to pass query string from master page and how to get that in view Products.aspx page it should display results based on menu id.
Thanks in advance
推荐答案
更改
change
Response.Redirect("~/View Products.aspx?MenuId=" +Menu1.SelectedItem.Value);
到
to
Response.Redirect("~/View Products.aspx?MenuId=" +e.Item.Text);
并使用参数化的sql语句
int id;
and also use parameterized sql statement
int id;
if (!int.TryParse(Request.QueryString["MenuId"], out id))
{
string sql = "select * from rsa_ProductItemTable where MenuId=@id";
SqlDataAdapter da = new SqlDataAdapter(sql, con);
da.SelectCommand.Parameters.AddWithValue("@id", id);
DataSet ds = new DataSet();
da.Fill(ds);
DataList1.DataSource = ds;
DataList1.DataBind();
con.Close();
}
这篇关于如何将查询字符串从母版页菜单控件传递到内容页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!