Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGrid <asp:hyperlink>

Status
Not open for further replies.

onedizzydevil

Programmer
Mar 24, 2001
103
US
By using a datagrid I created a list of records, in order to get more information about a record you need to click on the record title. How can I create a hyperlinked record title that has the record unique identifier (in this case gid) as part of the hyperlink (i.e. test.aspx?gid=1234). Below I have pasted in some code that found on several other websites but it does not seem to work, how is {0} suppose to do anything where it is at. I know this is suppose to represent the ordinal number of the column from the database and it does if it where to actually work but the only thing that gets past is {0}. Additionally, I have tryed putting in '[tt]NavigateUrl=&quot;test.aspx?gid=<%# Container.DataItem(&quot;gid&quot;)%>&quot;[/tt]' and '[tt]NavigateUrl=&quot;test.aspx?gid=&quot; & <%# Container.DataItem(&quot;gid&quot;)%>&quot;[/tt]' but neither work. I do have the datakeyfield set to gid if that can be used.

Any ideas?

//sample code received from serveral websites//
<asp:TemplateColumn>
<ItemTemplate>
<asp:HyperLink NavigateUrl=&quot;test.aspx?gid={0}&quot;><%# Container.DataItem(&quot;label&quot;)%></asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>


Thanks!


Wayne Sellars

&quot;Programming, today is a race between software developers, striving to build bigger and better idiot-proof programs, and the Universe, trying to produce bigger and better idiots. So far, Universe 1 - Programmers 0.&quot;
 
Hey Wayne,

Well, you could do this:
Have your hyperlink button column say Select or some token thing. When they click it, in the DataGrid.ItemCommand sub, grab the gid from the e.Item.Cell(indexofcell), and then jsut do a Response.Redirect(&quot;test.aspx?gid=&quot; & gid-value)

Not sure if the e.Item.Cell() is the write syntax, but you get the idea: go through the collections of the selected item until you can drill down to the GID value.

Jack
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top