Datagrid hyperlink based on multiple columns?

Josh K 81 Reputation points
2021-07-26T16:17:58.573+00:00

One of my pages displays a datagrid that includes an equipment serial number and a route assignment number. A single serial number can be indirectly associated with more than one route number. That wasn't the original design (it used to be one S/N to one route). The serial number is the ID field that is used for the hyperlink in the datagrid. The page the user is redirected to when clicking the link displays the serial number and the route number. If a device is associated with more than one route, the page will display the first route number found for that device even if it isn't the one the user selected. How can I set up the hyperlink to use both the serial number and the route number? Language is C#. The search results need to display additional info about the device, so the serial number still has to be used to pull that other data. Screen shots are below. Thanks!!

117967-datagrid-1.jpg118003-datagrid-2.jpg

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,483 questions
{count} votes

Accepted answer
  1. Albert Kallal 5,251 Reputation points
    2021-07-27T19:49:12.483+00:00

    Well, it seems to me the issue is that you now simple need to pass two paramters to the target web page.

    So, that target page now needs to accept two values in palce of one???

    so you want say this

    target url = "~/item.aspx?id="some serialnumber&routeid="some route id"

    I mean, drop the link button, just drop in a plane jane asp.net button. Say like this:

    118404-image.png

    And then for the button code, do something like this:

    protected void cmdView_Click(object sender, EventArgs e)  
    {  
        Button cBtn = (Button)sender;  
      
        DataGridItem dRow = (DataGridItem)cBtn.Parent.Parent;  
      
        var strURL = "~/item.aspx?id=" + dRow.Cells[4].Text +   
          "&routeID=" + dRow.Cells[2].Text;  
      
        Response.Redirect(strURL);  
    }  
    

    So, there is really nothing stopping you from using a plane jane asp.net button, and then grabbing the clicked row, and then building a correct URL with the two required values.

    The target page now on page load will need to get/grab/use the two values passed - not the one value.

    You could also probably cobble together a valid url expression in the mark-up, but then again just drop in a plane jane asp.net button - some code behind, and you off to the races so to speak.

    So drop in a button - add the click event. Then just write a few lines of code, build the correct URL, and then just jump to that target page.

    Edit: as a fyi? how do you add the click event to the button? (you can't display property sheet, and you can't double click on the button to jump to the code behind code stubb. But what you do this while in markup type in OnClick and when you hit the "=", then this popup appears in code editor:

    118441-image.png

    Now, you can choose create new event - it SEEMS like nothing occurs- but if you go to code behind, you see/find the code stub. And note how we pick up the full row by using Parent Parent. The data bound controls are in the cells collection. But tempated text boxes require use of findcontrol.

    Regards,
    Albert D. Kallal (Access MVP 2003-2017)
    Edmonton, Alberta Canada

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Josh K 81 Reputation points
    2021-07-27T13:30:59.517+00:00

    Yes, that's right. I need the target page to display the serial number and the route number. By only using the serial number as the search criteria, if that serial number is tied to more than one route number, the target page doesn't necessarily display the correct route number.

    0 comments No comments

  2. Josh K 81 Reputation points
    2021-07-27T20:26:04.607+00:00

    Thanks, that looks like it should work. Much appreciated.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.