How to make asp:BoundColumn a URL

R

Randall Parker

Using ASP.Net v1.1 with C#.

I have an asp:DataGrid where one column is specified as follows:

<asp:BoundColumn HeaderText="Serial" DataField="owner_serial_num"></asp:BoundColumn>

I might get a serial number of X01 or X02 for example. What I want to do is make that
serial number be a link to a different page like, say,

http://currentURLpath/DetailViewer.aspx&serial="X02"

So the idea is that the X02 row would have a URL for the serial number column which
also embedded in that URL an argument to which detail record to display if the user
clicks on it.

What confuses me is that the asp:BoundColumn is already showing the X02 text that I'd
want to surround with the a href HTML link tag. So do I put the link inside the
asp:BoundColumn or do I tell the BoundColumn tag something that lets me put the link
inside of it?

Any hints on how to do this? I'm an ASP.Net novice and confused.
 
L

Lars-Erik Aabech

Hi, Randall! :)

Here's a ton of information for you:
http://msdn.microsoft.com/library/en-us/dnaspp/html/creatingcustomcolumns.asp?frame=true

Short hint:
Use a TemplateColumn with a DataBound HyperLink inside.
Instead of
<asp:BoundColumn HeaderText="Serial"
DataField="owner_serial_num"></asp:BoundColumn>
use
<asp:TemplateColumn HeaderText="Serial">
<ItemTemplate>
<asp:HyperLink id="hyperlink1"
NavigateUrl='<%#
"http://currentURLpath/DetailViewer.aspx&serial=" +
DataBinder.Eval(Container, "DataItem.owner_serial_num") %>'
Text='<%# DataBinder.Eval(Container,
"DataItem.owner_serial_num") %>'
runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>


HTH,
Lars-Erik
 
G

Guest

dear parker;
yes you have to add some string on the tag to pull the needed str.ng from
the db and give the link that you give the url that you want.
here is an example that i use it in a repeater which pulls the url of a
photo over it it my give you a hint how to do it since it is the same code
that maybe used over the data grid bond column
<asp:HyperLink ID="newslink" Runat="server"
NavigateUrl='<%#"news/shownews.aspx?newsID="+DataBinder.Eval(Container,
"DataItem.ID")+"&catid="+DataBinder.Eval(Container,
"DataItem.CatagoryMainID") %>' Font-Underline="false" Font-Overline="false">
this is the section that is most neded for you
<%#"news/shownews.aspx?newsID="+DataBinder.Eval(Container,
"DataItem.ID")+"&catid="+DataBinder.Eval(Container,
"DataItem.CatagoryMainID") %>
here you see the databinder.eval section you can use it in your code like
this;

http://currentURLpath/DetailViewer.aspx&serial="+DataBinder.Eval(Container,
"DataItem.CatagoryMainID")
and here you must enter the values of CatagoryMainID in your db as you like
and bind it so it will show you deffrent url over each row of that column.
Not : you can change "CatagoryMainID" name as you like and accourding to
name that you but in your db
i hope this hint may help you
 
R

Remy Blaettler

You can just use a HyperLink column.

URL field:
owner_serial_num

URL format string:
DetailViewer.aspx&serial={0}
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Top