Hyperlink in datagrid

wheelerware

New member
Joined
May 16, 2003
Messages
4
Im trying to use a datagrid and add a hyperlink column. - easy enough -
I want to be able to make a decision based on the data in the dataset to either show a hyperlink or show text. (i.e. If the record in the table is from my userid, allow me to link to an edit page)

any clues on how to do this?
 
Runtime - the best that I could come up with is to use a case statement in the stored proc and return a hyperlink - not quite the solution that I was looking for
 
Originally posted by wheelerware
Runtime - the best that I could come up with is to use a case statement in the stored proc and return a hyperlink - not quite the solution that I was looking for

I would bind a procedure to the Databind event of the datagrid and check the value of the column your wanting to check and determin there wether you need a link or not. ler me see if I can find you some good example code
 
Code:
<asp:DataGrid id="Datagrid1" runat="server" AutoGenerateColumns="True" OnItemDataBound="Datagrid1_OnItemDataBound"/>

Sub Datagrid1_ItemDataBound(source As Object, e As DataGridItemEventArgs)
  If (e.Item.ItemType = ListItemType.Item Or _
    e.Item.ItemType = ListItemType.AlternatingItem) Then
    If Convert.ToDateTime(e.Item.Cells(1).Text) < DateTime.Today Then _
    e.Item.Cells(1).BackColor = System.Drawing.Color.FromName("#ffccff")
    If e.Item.DataItem("UserID") = 590 Then _
    e.Item.Cells(2).BackColor = System.Drawing.Color.DeepPink
  End If
End Sub

this sample code sets the back color based on the value its about to bind to the grid I am sure you can put a pace holder in the column you want the link or non link to be and generate the control and add it to the controls collection. Thats how I would do it any ways. If you need help email me Chris@qtmedical.com
 
Back
Top