Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Datagrid Control (http://www.velocityreviews.com/forums/f60-asp-net-datagrid-control.html)
-   -   want to make column in DataGrid a Hyperlink (http://www.velocityreviews.com/forums/t762895-want-to-make-column-in-datagrid-a-hyperlink.html)

Henry Jones 07-21-2006 11:57 PM

want to make column in DataGrid a Hyperlink
 
I am new to ASP.NET and I'm using Visual Studio 2003. I put a datagrid on a
form and bound to the Northwind/Orders table. The first column is the ID
field. How can I make the ID field display as a hyperlink on the grid when
the web form is displayed?

Thanks



Ken Cox [Microsoft MVP] 07-23-2006 02:34 PM

Re: want to make column in DataGrid a Hyperlink
 
Hi Henry,

You need to use a template column. See the code below to give you the idea.

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]

<%@ Page Language="VB" %>

<script runat="server">

Function CreateDataSource() As Data.DataTable
Dim dt As New Data.DataTable
Dim dr As Data.DataRow
dt.Columns.Add(New Data.DataColumn _
("URLvalue", GetType(String)))
dt.Columns.Add(New Data.DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New Data.DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New Data.DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 5
dr = dt.NewRow()
dr(0) = i.ToString & ".aspx"
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i <> 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
If Not IsPostBack Then
dg3.DataSource = CreateDataSource()
dg3.DataBind()
End If
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Check a checkbox</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:datagrid id="dg3" runat="server" autogeneratecolumns="False">
<columns>
<asp:templatecolumn headertext="Link">
<itemtemplate>
<asp:hyperlink runat="server" navigateurl='<%#
DataBinder.Eval(Container, "DataItem.URLvalue") %>' target="_blank"
text='<%# DataBinder.Eval(Container, "DataItem.StringValue")
%>'></asp:hyperlink>
</itemtemplate>
</asp:templatecolumn>
</columns>
</asp:datagrid>
</div>
</form>
</body>
</html>


"Henry Jones" <henryjones@yada.com> wrote in message
news:uLPFoFSrGHA.4348@TK2MSFTNGP02.phx.gbl...
>I am new to ASP.NET and I'm using Visual Studio 2003. I put a datagrid on
>a form and bound to the Northwind/Orders table. The first column is the ID
>field. How can I make the ID field display as a hyperlink on the grid when
>the web form is displayed?
>
> Thanks
>





All times are GMT. The time now is 11:50 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.