1

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.

User970008
  • 1,135
  • 3
  • 20
  • 49

2 Answers2

1

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>
Khan
  • 17,904
  • 5
  • 47
  • 59
  • There are two parameters. One is the ID the other is the dynamic title that appears where the Link text goes. Do I have to bind that separately too? – User970008 Mar 14 '12 at 18:01
  • Your binding occurs once. Look at it as specifying where to place the values of properties. See my edit, hopefully it helps. – Khan Mar 14 '12 at 18:45
0

Try the following code: navigateurl= '<%# string.Format("~\page.aspx?id={0}", DataBinder.Eval(Container.DataItem, "ID"))%>'

Also ensure that the DataSet is bound to the control from the code behind.

Anil Mathew
  • 2,590
  • 1
  • 15
  • 15