Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to pass QueryString values in Asp:HyperlinkColumn

How to pass QueryString values in Asp:HyperlinkColumn

Scheduled Pinned Locked Moved ASP.NET
tutorialquestion
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    just4ulove7
    wrote on last edited by
    #1

    Hi, How can I pass two querystring variables in asp:HyperlinkColumn... This is the one I am passing, I need to pass another variable too.... Is it possible to pass multiple querystring values... thanks

    S M 2 Replies Last reply
    0
    • J just4ulove7

      Hi, How can I pass two querystring variables in asp:HyperlinkColumn... This is the one I am passing, I need to pass another variable too.... Is it possible to pass multiple querystring values... thanks

      S Offline
      S Offline
      Shawn_H
      wrote on last edited by
      #2

      Disclaimer, Im only a newbie, and there is probably a better way..with that said I do something similar, but I handle it through the ItemDataBound Event. However when I first Bind my datagrid to my dataset, I create a new column for Href and for each record in the in the result set, I create the associated query string with the proper ID's. The below line is located in my BindGrid Function For Each categoryRow In DepartmentRow.GetChildRows(dr) aNewRow = Ds.Tables("Menu").NewRow aNewRow.Item(0) = DepartmentRow.Item(0) aNewRow.Item(1) = categoryRow.Item(1) aNewRow.Item(2) = "?DID=" & DepartmentRow.Item(0).ToString & "&CID=" & categoryRow.Item(1).ToString aNewRow.Item(3) = "   " & categoryRow.Item(2).ToString 'Add the cat row to the main datatable Ds.Tables("Menu").Rows.Add(aNewRow) Next categoryRow DataGrid1.DataSource = Ds.Tables(0).DefaultView DataGrid1.DataBind() DataGrid1.Columns(0).Visible = True DataGrid1.Columns(1).Visible = False DataGrid1.Columns(2).Visible = False DataGrid1.Columns(3).Visible = True This Href column is a hidden column in my datagrid, then in the ItemDataBound event,I can access this QueryString for each record like this and assign it to the LinkButton's NavigateUrl Property: Protected Sub DataGrid1_ItemBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs) Handles DataGrid1.ItemDataBound If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then Dim qryString As String = CType(e.Item.DataItem, DataRowView)(2).ToString CType(e.Item.FindControl("linkname"), HyperLink).NavigateUrl = PathPrefix() & qryString CType(e.Item.FindControl("mnuCell"), HtmlTableCell).Attributes.Add("onClick", "document.location.href='" & PathPrefix() & qryString & "'") End If End Sub Remember the Column indexed 2 (the third colum) in my datagrid is hidden, but this way I have it there on the first binding, and on all postbacks. Hope this helps

      1 Reply Last reply
      0
      • J just4ulove7

        Hi, How can I pass two querystring variables in asp:HyperlinkColumn... This is the one I am passing, I need to pass another variable too.... Is it possible to pass multiple querystring values... thanks

        M Offline
        M Offline
        minhpc_bk
        wrote on last edited by
        #3

        Hi there, With the HyperLinkColumn, you can only specify a single data field for the column, so you cannot pass multiple parameters to the query string. Using the code-behind suggested by Shawn is an option, and there is a simple way is to use a template column with a hyperlink control:

        asp:TemplateColumn
        <ItemTemplate>
        <asp:HyperLink runat="server" Text="MileStoneId"
        NavigateUrl='<%# "CreateMileStone.aspx?MileStoneId=" +
        Container.DataItem("MileStoneId") +
        "&MileStoneText=" + Container.DataItem("MileStoneText") %>' />
        </ItemTemplate>
        </asp:TemplateColumn>

        S 1 Reply Last reply
        0
        • M minhpc_bk

          Hi there, With the HyperLinkColumn, you can only specify a single data field for the column, so you cannot pass multiple parameters to the query string. Using the code-behind suggested by Shawn is an option, and there is a simple way is to use a template column with a hyperlink control:

          asp:TemplateColumn
          <ItemTemplate>
          <asp:HyperLink runat="server" Text="MileStoneId"
          NavigateUrl='<%# "CreateMileStone.aspx?MileStoneId=" +
          Container.DataItem("MileStoneId") +
          "&MileStoneText=" + Container.DataItem("MileStoneText") %>' />
          </ItemTemplate>
          </asp:TemplateColumn>

          S Offline
          S Offline
          Shawn_H
          wrote on last edited by
          #4

          Ahhh Yes minhpc, I knew if I stuck my neck out there you would reveal a better way....thanks! Shawn

          M 1 Reply Last reply
          0
          • S Shawn_H

            Ahhh Yes minhpc, I knew if I stuck my neck out there you would reveal a better way....thanks! Shawn

            M Offline
            M Offline
            minhpc_bk
            wrote on last edited by
            #5

            Wow, Shawn! You might have no idea that I was just about to post a reply to your post to let you know that you can use the databinding expressions to populate the NavigateUrl property. :). In fact, creating an additional field which is the result of combining other fields is also an option.

            S 1 Reply Last reply
            0
            • M minhpc_bk

              Wow, Shawn! You might have no idea that I was just about to post a reply to your post to let you know that you can use the databinding expressions to populate the NavigateUrl property. :). In fact, creating an additional field which is the result of combining other fields is also an option.

              S Offline
              S Offline
              Shawn_H
              wrote on last edited by
              #6

              So you mean creating an additional field in the original dataset like I did in my example, but then Binding it in the aspx page like you showed in your example, but just binding to the one field (The one you create by making the whole query string)? I hope that made sense Shawn

              M 1 Reply Last reply
              0
              • S Shawn_H

                So you mean creating an additional field in the original dataset like I did in my example, but then Binding it in the aspx page like you showed in your example, but just binding to the one field (The one you create by making the whole query string)? I hope that made sense Shawn

                M Offline
                M Offline
                minhpc_bk
                wrote on last edited by
                #7

                Yes, if you create an additional field in the dataset, you just bind the control to this single field. If you don't like creating a new field, then you can use databind epxressions for multiple fields, and finally concatenate them. You can take a look at this document: Data Binding Expression Syntax[^]

                J 1 Reply Last reply
                0
                • M minhpc_bk

                  Yes, if you create an additional field in the dataset, you just bind the control to this single field. If you don't like creating a new field, then you can use databind epxressions for multiple fields, and finally concatenate them. You can take a look at this document: Data Binding Expression Syntax[^]

                  J Offline
                  J Offline
                  just4ulove7
                  wrote on last edited by
                  #8

                  Thanks a lot :)

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups