Results 1 to 6 of 6

Thread: [RESOLVED] Hyperlink in datagrid?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2004
    Location
    cainta
    Posts
    80

    Resolved [RESOLVED] Hyperlink in datagrid?

    Hi,

    asp.net code
    using datagrid, column1 is my hyperlink and column2 is the database value.

    Column1 Column2
    View Info anm

    Q: How can I get the result from my hyperlink that should be like this "name.aspx?nme=asp".


    Thanks

  2. #2
    Member basilisk's Avatar
    Join Date
    Jan 2002
    Posts
    32

    Re: Hyperlink in datagrid?

    you would set up the hyperlink column something like this:

    VB Code:
    1. <asp:HyperLinkColumn
    2.                 HeaderText="Column1"
    3.                 DataNavigateUrlField="name"
    4.                 DataNavigateUrlFormatString="name.aspx?name={0}"
    5.    
    6.                 Text="View Info"  />

    where DataNavigateUrlField is the field in the datasource which will provide the URL of the page. So if you have a unique ID field in the datasource called 'ID' you would put DataNavigateUrlField="ID" if you have a field called name which is unique then substitute name for ID.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2004
    Location
    cainta
    Posts
    80

    Re: Hyperlink in datagrid?

    Thanks Bro!

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jun 2004
    Location
    cainta
    Posts
    80

    Re: Hyperlink in datagrid?

    Quote Originally Posted by basilisk
    you would set up the hyperlink column something like this:

    VB Code:
    1. <asp:HyperLinkColumn
    2.                 HeaderText="Column1"
    3.                 DataNavigateUrlField="name"
    4.                 DataNavigateUrlFormatString="name.aspx?name={0}"
    5.    
    6.                 Text="View Info"  />

    where DataNavigateUrlField is the field in the datasource which will provide the URL of the page. So if you have a unique ID field in the datasource called 'ID' you would put DataNavigateUrlField="ID" if you have a field called name which is unique then substitute name for ID.

    Basilisk,

    thanks for your reply...

    Q: how about adding a value of textbox in HyperLinkColumn? 2 fields?

    DataNavigateUrlFormatString="name.aspx?name={0}&xcde=???"

  5. #5
    Member basilisk's Avatar
    Join Date
    Jan 2002
    Posts
    32

    Re: Hyperlink in datagrid?

    having two fields in the hyperlink column is rather more difficult and the only way i have got this to work is to use a templatecolumn instead of a hyperlink column and then put the asp:hyperlink inside it like so:

    VB Code:
    1. <asp:templatecolumn HeaderText="Details" Visible="true">
    2.    <itemtemplate>
    3.        <asp:HyperLink id="HyperLink1" runat="server"
    4.     Text="View Info" NavigateUrl='<%# "name.aspx?" + DataBinder.Eval(Container.DataItem,"fieldname1","name={0}") + "&" +DataBinder.Eval(Container.DataItem,"fieldname2","xcde={0}")%>'>
    5.        </asp:HyperLink>
    6.  
    7.    </itemtemplate>
    8. </asp:templatecolumn>

    you will need to substitute the fieldnames/column names of your datatable that you need picked up for fieldname1 and fieldname2.

    This will then give you a URL of this format:
    name.aspx?name=xxxx&xcde=yyyyy

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jun 2004
    Location
    cainta
    Posts
    80

    Re: Hyperlink in datagrid?

    Basilisk,

    thanks again!!!
    Last edited by Chowking; Aug 15th, 2005 at 09:37 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width