Click here to Skip to main content
15,883,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
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();
        }

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
Posted
Updated 6-Dec-14 5:27am
v2
Comments
DamithSL 6-Dec-14 11:29am    
can you update the question with how your menu code in master page and how you handle the menu click events
kwelpooh 6-Dec-14 11:48am    
<asp:MenuItem ImageUrl="~/Admin/images/Button/Products.png" ToolTip="hower to see products">
<asp:MenuItem ToolTip="Hover to Mens Collections" Text="Mens">
<asp:MenuItem ToolTip="mens Clothing" Text="clothing">
<asp:MenuItem ToolTip="Shirts" Text="Shirts" NavigateUrl="~/View Products.aspx?MenuId={0}">
<asp:MenuItem ToolTip="Pants" Text="Pants">
<asp:MenuItem ToolTip="Tshirts" Text="Tshirts">


<asp:MenuItem ToolTip="Shirts" Text="Shirts" NavigateUrl="~/View Products.aspx?MenuId="Dont know what value come here">

protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
{

Response.Redirect("~/View Products.aspx?MenuId=" +Menu1.SelectedItem.Value(dont Know Whether its correct or not);
}
I think MenuId is null. Also use Parameterized query to avoid SQL Injection attacks.

1 solution

change
C#
Response.Redirect("~/View Products.aspx?MenuId=" +Menu1.SelectedItem.Value);

to
C#
Response.Redirect("~/View Products.aspx?MenuId=" +e.Item.Text);

and also use parameterized sql statement
int id;

C#
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();
}
 
Share this answer
 
v2
Comments
kwelpooh 6-Dec-14 12:02pm    
Thanks for your time . But menu id is not null I just want to make sure other coding is all correct. ?
DamithSL 6-Dec-14 12:06pm    
try with above code and check whether you still get the same error or not.
what is the column type of menuid in your database?
kwelpooh 6-Dec-14 12:19pm    
I will try that code & menu id is int
DamithSL 6-Dec-14 12:25pm    
that is the one of issue with your code, in your sql statement you have given menuid as string column with ' '
if it is int you can use
where MenuId=" + menuid;
without single quotes, but recommended way is using parameters.
kwelpooh 6-Dec-14 12:54pm    
I tried this code and it displays nothing kept break point and tried it takes menu id =0 but menu id in the not null.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900