ok so i have a page with a gridview on it and it displays rows from sql table. i have also a link assigned to each row:
Code
' />this works fine and the url that gets displayed is good. But i would like to send the our_ref attribute to the page itself aswell as the url and use it make further queries.
Thanks
G

Tahir AnsariRank #366 · 6.8K reputationPosted Apr 15, 2024, 3:02 PM EDT
To pass the our_ref attribute to the destination page, you can use either the query string or session variables. Here's how you can do it using a query string:
Then, on the destination page (MD_Overall.aspx), you can retrieve the our_ref value from the query string:
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Request.QueryString["our_ref"] != null) { string ourRef = Request.QueryString["our_ref"]; // Use the ourRef value to make further queries or operations } } }Jayraj ChhayaRank #304 · 8.2K reputationPosted Apr 16, 2024, 2:58 AM EDT
To achieve this functionality, you can utilize the
RowCommandevent of the GridView. When the hyperlink is clicked, theRowCommandevent is triggered, allowing you to access the row data and redirect to the target page with the necessary parameter.protected void GridViewMatters_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "ViewDetails") { int rowIndex = Convert.ToInt32(e.CommandArgument); GridViewRow row = GridViewMatters.Rows[rowIndex]; string ourRef = row.Cells[1].Text; // Assuming 'our_ref' is in the second cell // Redirect to the target page with the parameter Response.Redirect("MD_Overall.aspx?id=" + ourRef); } }In your GridView markup, modify the HyperLink control to trigger the
RowCommandevent:By using the
RowCommandevent and passing the row index as theCommandArgument, you can retrieve the necessary data from the GridView row and redirect to the target page with the parameter included in the URL.fergus72 reputationPosted Apr 16, 2024, 3:55 AM EDT
@Jayraj Chhaya when i run your snippet of code
the button click does not lik to next page