This is a migrated thread and some comments may be shown as answers.

[Solved] Hyperlink on Some Rows

1 Answer 93 Views
Grid
This is a migrated thread and some comments may be shown as answers.
PJ Rodriguez
Top achievements
Rank 1
PJ Rodriguez asked on 15 Mar 2010, 09:08 PM
I have a grid that will be populated from the database.

Some of the rows returned will require hyperlinks and some rows will not--this just depends on what is being called back from the database. For example:

CELL 1        CELL 2                                CELL 3
Data            Data (Hyperlinked)                 
Data            Data (Hyperlinked)                 
Data            Data (No Hyperlink)    
Data            Data (No Hyperlink)   
Data            Data (Hyperlinked)      

I was going to use the Hyperlink template of the RADGrid but that means it will always show up as if there is a hyperlink even though there isn't. Is there a way to accomplish this using RADGrid? Thanks.


PJ         

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 16 Mar 2010, 06:08 AM
Hi PJ,

You can access the column value in ItemDataBound event and set the NavigateUrl property for getting required result.

Use the following code snippet if you are using GridHyperLinkColumn.

C#:
protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e) 
        { 
            if (e.Item is GridDataItem) 
            { 
                GridDataItem item = (GridDataItem)e.Item; 
                HyperLink hlink = (HyperLink)item["CELL 2"].Controls[0]; 
 
                // Check for condition 
                if (hlink.Text == "Data (No Hyperlink)")                 
                    hlink.NavigateUrl = "";                
 
            } 
        } 

Here is the code snippet if you are using GridTemplateColumn with HyperLink.

C#:
protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e) 
        { 
            if (e.Item is GridDataItem) 
            { 
                GridDataItem item = (GridDataItem)e.Item; 
                HyperLink hlnk = (HyperLink)item.FindControl("hlnk"); 
 
                // Check for condition 
                if (hlnk.Text == "Data (No Hyperlink)"
                    hlnk.NavigateUrl = ""
 
            } 
        } 
 

Regards
Shinu.

Tags
Grid
Asked by
PJ Rodriguez
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or