Multiple URL Fields in a datagrid

Discussion in 'ASP .Net' started by Guest, Nov 24, 2004.

  1. Guest

    Guest Guest

    Hi there,

    I have a datagrid that is bound to a datasource. The grid has a hyperlink
    column and I want to generate the URL using the URL Field and URL Format
    String fields in the Property Builder.

    The problem I'm running into is trying to generate the URL with more than
    one URL Field entry. I need to have more than field but I can't figure out
    how to add more than one field in the URL Field textbox. Is it possible?

    I would want the URL Format String to look something like...


    Any help would be greatly appreciated.

    Guest, Nov 24, 2004
    1. Advertisements

  2. Guest

    Joe Fallon Guest

    You can't do it using a normal bound column.
    You need a template column.

    Then in the dg_ItemDataBound event you create an instance of the hyperlink
    and find it using FindControl and then set its properties.
    In this case the dg is bound to a collection and the index of the collection
    equals the index of the grid. So you can always identify whcih row you are

    <asp:TemplateColumn SortExpression="myColumn" HeaderText="My Header">
    <asp:Hyperlink id="hylMyColumn"

    Private Sub dg_ItemDataBound(ByVal sender As Object, ByVal e As
    DataGridItemEventArgs) Handles dg.ItemDataBound
    If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
    ListItemType.AlternatingItem Then

    'need to take paging into account!
    Dim mIndex As Integer = CType(sender, DataGrid).PageSize *
    CType(sender, DataGrid).CurrentPageIndex + e.Item.ItemIndex

    'set hyperlinks values:
    'Note: in the HTML the &nbsp; is required because the grid cells will
    change shape w/o it when there is no data.

    Dim ohylMyColumn As HyperLink =
    CType(e.Item.FindControl("hylMyColumn"), HyperLink)

    ohylMyColumn.NavigateUrl =
    "javascript:LeftSideWin('ViewSomePage.aspx?Key=" & mCollection(mIndex).key &
    "&KeyType=" & mCollection(mIndex).keytype & "','MyScreen');"

    oHylInvNumber.Text = mCollection(mIndex).MyDescription

    End If
    End Sub
    Joe Fallon, Nov 25, 2004
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.