.nethyperlinkdatafield

.Net Copy ID Datafield into a Hyperlink Navigate URL parameter


I have a .Net 2.0 project where I'd like to take the value from the ID boundfield and pass that to the query string constructor of a Hyperlink field's navigate URL.

<asp:BoundField HeaderText="ID" DataField="ID"></asp:BoundField>
<asp:hyperlinkfield HeaderText="Page Link" DataTextField="title" text="{0}" navigateurl="~\page.aspx?id={THE ID VALUE}" />

So in each row, the link would have the ID of the page in the querystring.

<a href="page.aspx?id=1234">

I don't know if DataControlField.CloneField Method or CopyProperties might be of any help. Is so, can you post an example of how to use them in this case?

In the codebehind, I do not have any databinding events. I have a Viewstate which is filled from the dataset of a SQL View.


Solution

  • I assume you're using a GridView control.

    Here is an example of how you can achieve what you're trying to do:

    <asp:GridView ID="myGridView" runat="server" AutoGenerateColumns="false">
        <Columns>
            <asp:BoundField HeaderText="ID" DataField="ID"></asp:BoundField>        
            <asp:TemplateField>
                <ItemTemplate>
                    <a href="page.aspx?id=<%# Eval("ID") %>"><%# Eval("DynamicTitle") %></a>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>