Binding two fields in the DataNavigateUrlFormatString

Discussion in 'ASP .Net Web Controls' started by genc_ymeri, Mar 23, 2006.

  1. genc_ymeri

    genc_ymeri Guest

    Hi,
    I would like to bind the hyperlink column but I don't see how to.

    I tried somethink like this but instead of showing ID nummbers it shows
    "ID=ID"

    Any tip is very much appreciated.

    Genc


    PS:
    Code I tested with

    aHLCol.DataTextField = "RR_ID"

    aHLCol.DataNavigateUrlField = "FILEPATH"

    aHLCol.DataNavigateUrlFormatString = "{0}?ID=" &
    resultTable.Column("ID").ToString ()

    aHLCol.HeaderText = "http:/cnn.com/{0}"

    dgSearchResults.Columns.Add(aHLCol)

    dgSearchResults.DataSource = resultTable

    dgSearchResults.DataBind()
     
    genc_ymeri, Mar 23, 2006
    #1
    1. Advertising

  2. genc_ymeri

    Guest

    I'm guessing you want the url's ID parameter to be set to the ID column
    of first row in the results table.

    aHLCol.DataNavigateUrlFormatString="{0}?ID=" &
    resultTable.Rows(0)("ID").ToString()
     
    , Mar 23, 2006
    #2
    1. Advertising

  3. genc_ymeri

    genc_ymeri Guest

    Not really, my table has two columns formName and RecordID so I would like
    something like the {0} does but for another datafield. eg. below


    DataNavigateUrlFormatString="{0}?ID=" &
    resultTable.Columns("ID").ToString() updated to each row.

    so the DataNavigateUrlFormatString would be




    form=f1&ID=1
    form=f2&ID=2
    form=f3&ID=3

    where fn & n values are the values of the formName & its ID in the n-row.

    Genc.




    <> wrote in message
    news:...
    > I'm guessing you want the url's ID parameter to be set to the ID column
    > of first row in the results table.
    >
    > aHLCol.DataNavigateUrlFormatString="{0}?ID=" &
    > resultTable.Rows(0)("ID").ToString()
    >
     
    genc_ymeri, Mar 23, 2006
    #3
  4. genc_ymeri

    Guest

    Hmm, that's a tough one. I believe you can handle the ItemBound event
    and modify the url within the hyperlinkcolumn. Never had the occasion
    to do what you need but I think the code below would illustrate my
    point.

    aHLCol.DataNavigateUrlFormatString = "{0}?ID=<RecordID>" 'the real
    data would be substituted with the real data during ItemBound.

    AddHandler dgSearchResults.ItemBound, AddressOf DGItemBound

    dgSearchResults.Columns.Add(aHLCol)
    dgSearchResults.DataSource = resultTable
    dgSearchResults.DataBind()

    'Assume aHLCol is the 1st column in the DataGrid
    Sub DGItemBound(sender As Object, e As DataGridItemEventArgs)
    If e.Item.ItemType = ListItemType.Item Or _
    e.Item.ItemType = ListItemType.AlternatingItem Then

    'Replace <RecordID> in the 1st column with the correct
    value from resultTable
    e.Item.Cells(0).Text =
    e.Item.Cell(0).Text.Replace("<RecordID>",
    resultTable.Rows(e.Item.ItemIndex)("RecordID"))
    End If
    End Sub

    That is another reason I prefer to work with GridView.
    Good luck.
     
    , Mar 23, 2006
    #4
  5. genc_ymeri

    genc_ymeri Guest

    > aHLCol.DataNavigateUrlFormatString = "{0}?ID=<RecordID>" 'the real
    > data would be substituted with the real data during ItemBound.


    Yes ! you are right....

    I assumed MS should provide the means without going extra steps b/c already
    it provides half of it, the DataNavigateUrl.

    I kept trying something like

    DataNavigateUrl = "f1, f2" or {"f1","f2"}

    thinking that's the most likely MS had implemeted that (following the
    pattern)....... As you showed, I could have manipulated the datagrid in
    its events as well I could have manipulated the ds adding another column on
    the fly before binding etc..,,,,,

    Interesting enough, after google it, I read that my assumed "way" of doing
    it, it is implemented in .Net 2.0 (I haven't try it though)

    What did as a quick solution is that I added another column in my sql
    stamement select '<a href= .......' and resolved everything ...........


    Thanks a lot and very much appreciated,
    Genc.

    <> wrote in message
    news:...
    > Hmm, that's a tough one. I believe you can handle the ItemBound event
    > and modify the url within the hyperlinkcolumn. Never had the occasion
    > to do what you need but I think the code below would illustrate my
    > point.
    >
    > aHLCol.DataNavigateUrlFormatString = "{0}?ID=<RecordID>" 'the real
    > data would be substituted with the real data during ItemBound.
    >
    > AddHandler dgSearchResults.ItemBound, AddressOf DGItemBound
    >
    > dgSearchResults.Columns.Add(aHLCol)
    > dgSearchResults.DataSource = resultTable
    > dgSearchResults.DataBind()
    >
    > 'Assume aHLCol is the 1st column in the DataGrid
    > Sub DGItemBound(sender As Object, e As DataGridItemEventArgs)
    > If e.Item.ItemType = ListItemType.Item Or _
    > e.Item.ItemType = ListItemType.AlternatingItem Then
    >
    > 'Replace <RecordID> in the 1st column with the correct
    > value from resultTable
    > e.Item.Cells(0).Text =
    > e.Item.Cell(0).Text.Replace("<RecordID>",
    > resultTable.Rows(e.Item.ItemIndex)("RecordID"))
    > End If
    > End Sub
    >
    > That is another reason I prefer to work with GridView.
    > Good luck.
    >
     
    genc_ymeri, Mar 25, 2006
    #5
  6. genc_ymeri

    Guest

    Hi Genc,

    Please post the other way of binding multiple parameters to
    DataNavigateUrl because I think my idea of replacing the parameter
    during ItemBound is a bit of a bodge.

    Regards,
    Andy
     
    , Mar 30, 2006
    #6
  7. You can do this
    <asp:HyperLink runat="server" Text="View"
    NavigateUrl='<%# "urpage.aspx?ID=" & _
    Container.DataItem("urID") & _
    "&showpage=" & Container.DataItem("secondID")
    %>' />
    Hope that helps
    Patrick


    "" <> wrote in message
    news:...
    > Hi Genc,
    >
    > Please post the other way of binding multiple parameters to
    > DataNavigateUrl because I think my idea of replacing the parameter
    > during ItemBound is a bit of a bodge.
    >
    > Regards,
    > Andy
    >
     
    Patrick.O.Ige, Mar 30, 2006
    #7
  8. genc_ymeri

    Guest

    Thanks. And why did I not think of it?

    Regards,
    Andy
     
    , Mar 30, 2006
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Coder Coder

    DataNavigateUrlFormatString

    Coder Coder, Jul 9, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    7,260
    Joshua Flanagan
    Aug 6, 2003
  2. Raymond

    DataNavigateUrlFormatString

    Raymond, Jul 11, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    541
    Raymond
    Jul 11, 2003
  3. Mike P

    DataNavigateUrlFormatString

    Mike P, Aug 11, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    3,707
    satheshram
    Oct 10, 2008
  4. genc_ymeri
    Replies:
    7
    Views:
    4,333
  5. AMT2K5
    Replies:
    1
    Views:
    199
    Eric Schwartz
    Nov 8, 2005
Loading...

Share This Page