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

Selective formatting for link

3 Answers 62 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Austinguy
Top achievements
Rank 1
Austinguy asked on 17 Mar 2010, 07:08 PM
Hi,

I'm new to the grid control/asp.net programming and need this solution rather urgently, help is appreciated.

I'm creating a link URL in my table but only want the field to have a hotlink if it is active, else show data and no hotlink.

how do i do this?
the item template is:

<telerik:GridTemplateColumn ItemStyle-HorizontalAlign="Right" HeaderText="Matches"
                            DataField="Matches">
                            <ItemTemplate>
                                <div class="grid_4 center">
                                    <a href="<%#Eval("MatchesURL") %>" class="blueLink" style="font-weight:bold;">
                                        <%#Eval("Matches")%>
                                    </a>
                                </div>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn> 

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 18 Mar 2010, 10:42 AM

Hello Austinguy,

I guess you want to set the link as active/inactive based on cell value of corresponding row. You can access theHtmlAnchor control in code behind and set the HRef property to false in order to set as inactive.

C#:

 
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)  
    {  
        if (e.Item is GridDataItem)  
        {  
            GridDataItem item = (GridDataItem)e.Item;  
            HtmlAnchor hlnk = (HtmlAnchor)item.FindControl("hLink");  
 
            // Check for condition   
            if (item["ID"].Text == "ID1")  
                hlnk.HRef = "";  
        }   
    } 

Note: Also add id="hLink" and add runat="server" to anchor (in aspx) in order to access the control on server.

-Shinu.

0
Austinguy
Top achievements
Rank 1
answered on 18 Mar 2010, 09:17 PM
Shinu,
Thanks for your response.  However I'm having an issue:

when I add the runat="server" tag, I get an error saying the server tag is not well-formed.

<a href="<%#Eval("MatchesURL") %>" class="blueLink" style="font-weight:bold;" id="hlink" runat="server">

I'm not sure what would be causing this issue, can anyone help with this please?

Also in the ItemDataBound code, i'm not able to get the hlnk object in the findcontrol... it throws an error as well.

thanks for your help.
0
Princy
Top achievements
Rank 2
answered on 19 Mar 2010, 08:47 AM
Hi,

Please change the double quotes to single quotes for the href as shown below:

<href='<%#Eval("MatchesURL") %>' class="blueLink" style="font-weight:bold;" id="hlink" runat="server"

Princy
Tags
Grid
Asked by
Austinguy
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Austinguy
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or