944,091 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Marked Solved
  • Views: 8397
  • ASP.NET RSS
Aug 4th, 2005
0

Data Grid: How to include Hyperlinks

Expand Post »
Hi all,
I have data grid:
In that i have to show different hyperlinks colors with type of memberships.
If gold member then Hyperlink is Green
If Silver member then Hyperlink is Red.
otherwise the Hyperlink shoudl be Blue !!!
How to achieve this is Data grid!!!.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Madhusudhan is offline Offline
3 posts
since Aug 2005
Aug 4th, 2005
0

Re: Data Grid: How to include Hyperlinks

try changing the column that has the hyperlink to a template column. then you can go into the (Databindings) property of the hyperlink and set the cssclass based on the type of membership.

For example, add these css classes to your css style sheet:

.gold a:link {color:green;}
.silver a:link {color: red;}
etc...

then you can either add a column to your data table to hold the type of membership or determine it programatically.

for example you can put this in the databinding for the hyperlink:
DataBinder.Eval(Container, "DataItem.memberType")

hope that made sense and helped!

-SelArom
Reputation Points: 20
Solved Threads: 1
Junior Poster in Training
SelArom is offline Offline
54 posts
since Oct 2004
Aug 11th, 2005
0

Re: Data Grid: How to include Hyperlinks

Hi Madhusudhan,

Your question inspired me to write some in-depth articles on the subject. :eek:

I have dealt with this same problem before. I ultimately created several custom template columns which satisfy most needs.

Adding Simple Columns to DataGrid (BoundColumn and HyperLinkColumn)

A Custom HyperLink Column Example Which Inherits from TemplateColumn

As I demonstrate in the second article you basically have two choices:

1) Perform some preprocessing on your DataTable after filling it from the database and before binding it to the DataGrid. For example, create another column, loop over all the rows and fill the added column with the HTML you want to display. Then you can bind that column to a simple BoundColumn on the Grid.

2) Use TemplateColumns where you have total control. Then once you define your DataGrid columns, there is no preprocessing of your DataTable required. You can bind the table directly to the grid after reading from the database.

If you need a quick and dirty solution, use 1), if you expect to run into this problem again, use 2).

For all the details and my custom link template column, check out the articles.

Cheers,
- Steve
Reputation Points: 10
Solved Threads: 3
Newbie Poster
cambia is offline Offline
17 posts
since Jul 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: what does assemblyinfo.cs consists of
Next Thread in ASP.NET Forum Timeline: How to control decimal poit





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC