Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I'm 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?

Posted
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

Posted

<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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...