Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to pas more than one value in querystring.. the code below show only one product in a grid.. which is a wrong result

here is the code on my main.aspx page

C#
protected void LinkButton4_Click(object sender, EventArgs e)
   {


                     string querydr = "select * from Products";
           SqlDataReader dr = obj.fillcomb(querydr);
           while (dr.Read())
           {
                proid = Convert.ToInt16(dr["ProductID"]); // what changes i have to make to make it work correctly
                Response.Redirect("ProductCatalog.aspx?ID=" + proid);


           }


       }

   }


and here is the page on my productcatalog.aspx page

C#
if (Request.QueryString["ID"] != "" && Request.QueryString["ID"] != null)
       {
           string query = "Select * from Products where ProductID= " + Convert.ToInt32(Request.QueryString["ID"].ToString()) + " AND UnitCost < 5000";
                      DataSet ds = obj.fillgrid(query);
           GridView1.DataSource = ds.Tables[0];
           GridView1.DataBind();
       }
Posted
Updated 25-Dec-11 5:25am
v6

hi frnd

you can write you logic as per below code

C#
string proid;
            string querydr = "select * from Products";
            SqlDataReader dr = obj.fillcomb(querydr);
            while (dr.Read())
            {
              if(proid == String.empty)
                  {
                 proid = Convert.ToInt16(dr["ProductID"]);
                 }
              else
                 {
              proid +=","+Convert.ToInt16(dr["ProductID"])
                }
            }

            Response.Redirect("your page name"?ID=proid);


and into another page:

C#
if(Request.QueryString["ID"] !=null && 
Request.QueryString["ID"].toString() != "")
{
 string query = "Select * from Products where ProductID= '" + Request.QueryString["ID"].ToString() + "' AND UnitCost &lt; 5000"; //request.querystring should
}


let me know is this solution is help.
 
Share this answer
 
v2
Hi,

defiantly it will show you one record from all your records, reason is Response.Redirect in your button click.

when you click on LinkButton4 it will redirect your page from Response.Redirect line so other code will not execute.

have a look at behavior of Response.Redirect.

you need to change your logic.

hope this will help you to resolving problem,

thanks
-amit.
 
Share this answer
 

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