wheelerware Posted May 16, 2003 Posted May 16, 2003 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? Quote
Moderators Robby Posted May 17, 2003 Moderators Posted May 17, 2003 Are you adding/formatting the dg at runtime or design-time? Quote Visit...Bassic Software
wheelerware Posted May 19, 2003 Author Posted May 19, 2003 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 Quote
Liqdfire Posted May 20, 2003 Posted May 20, 2003 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 Quote
Liqdfire Posted May 20, 2003 Posted May 20, 2003 <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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.