3
Answers

Getting the value of Query String

Harsh Jani

Harsh Jani

10y
805
1
Hi!
 
I have created a simple online shopping application, where if a user clicks on a product image he will be directed to the Product Details page. My question is how to get the Product Id of that particular Product that the user has clicked using query string. I have tried the following code.
 
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
Response.Redirect("Product_Details.aspx?Product_Id={0}");
}
 
In the Product details page, the code is as given below:-
 
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
FillDataList();
}
private void FillDataList()
{
cmd = new SqlCommand("select Product_Category_Name, Product_Id, Product_Name, Product_Image, Price from Product_Category_Mst a, Product_Mst b where a.Product_Category_Id = b.Product_Category_Id and Product_Id = @Product_Id", con);
 
int Product_Id = Convert.ToInt16(Request.QueryString["Product_Id"]);
cmd.Parameters.AddWithValue("@Product_Id", Product_Id);
 
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
DataList1.DataSource = dt;
DataList1.DataBind();
}
 
Kindly help me out in this regard. 
 
Answers (3)