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

Change text of custom linkbutton in CommandItemTemplate

5 Answers 117 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris LaFrancis
Top achievements
Rank 1
Chris LaFrancis asked on 23 Mar 2010, 08:58 PM
I have the following in the CommandItemTemplate tag:

 

<

 

CommandItemTemplate>

 

 

    <table width="100%">

 

 

        <tr>

 

 

            <td align="left">Third Party Mismatches</td>

 

 

            <td align="right">

 

 

                <asp:LinkButton ID="showFilter" runat="server" CommandName="DisplayFilter"

 

 

                    Text="Filter">

 

 

                </asp:LinkButton>

 

 

            </td>

 

 

        </tr>

 

 

    </table>

 

</

 

CommandItemTemplate>

 

 

 

 

 

 

 

 

 

What i want to do is when the user clicks on the showFilter link it will display or hide the folter depending on if it is shown already or not. I have that part working. What I can't get is to change the text to "Show Filter" if the filter is hidden and "Hide Filter" if it is shown.
I have the followinfg code but it isn't working.
Protected Sub GrdThirdParty_ItemCommand(ByVal source As Object, _  
                         ByVal e As GridCommandEventArgs) _  
                         Handles GrdThirdParty.ItemCommand  
 
        If e.CommandName = "DisplayFilter" Then 
            Dim lnkButton As LinkButton = CType(e.Item.FindControl("showFilter"), LinkButton)  
            If GrdThirdParty.AllowFilteringByColumn = False Then 
                GrdThirdParty.AllowFilteringByColumn = True 
                lnkButton.Text = "Hide Filter"  
            Else 
                GrdThirdParty.AllowFilteringByColumn = False 
                lnkButton.Text = "Show Filter" 
            End If 
            GrdThirdParty.MasterTableView.Rebind()  
        End If 
 
    End Sub 
Any ideas?
Thanks for the help.

5 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 24 Mar 2010, 07:00 AM

Hello Chris,

You can set the Text proeprty of the LinkButton directly from aspx page, instead of setting from code behind.

ASPX:

 
<CommandItemTemplate>  
    <table width="100%">  
        <tr>  
            <td align="left">  
                Third Party Mismatches  
            </td>  
            <td align="right">  
                <asp:LinkButton ID="showFilter" runat="server" CommandName="DisplayFilter" Text='<%# (RadGrid1.AllowFilteringByColumn) ? "Hide Filter" : "Show Filter"%>'>   
                </asp:LinkButton>  
            </td>  
        </tr>  
    </table>  
</CommandItemTemplate> 

-Shinu.

0
Chris LaFrancis
Top achievements
Rank 1
answered on 24 Mar 2010, 03:04 PM
Thanks for the reply but when I add the code I get an error that says the '?' character cannot be used here.
0
Dimo
Telerik team
answered on 26 Mar 2010, 09:56 AM
Hi Chris,

The following syntax is C#

(condition) ? if true : if false

You need to use the VB syntax, which is

Iif(condition, if true, if false)

http://www.google.com/search?q=vb+iif

Regards,
Dimo
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Matt DiPietro
Top achievements
Rank 1
answered on 17 Aug 2011, 04:39 PM
Is there any way to access that control from the client side?  I'm doing the exact same thing the OP is doing, except I'm showing/hiding the filter row using javascript and the grid.get_masterTableView().showFilterItem()/hideFilterItem() functions.  I'd like to be able to change the text of the link as well if possible.
0
Matt DiPietro
Top achievements
Rank 1
answered on 17 Aug 2011, 08:24 PM
Nevermind.  I figured out a way to do this by passing the control id to the javascript function.
Tags
Grid
Asked by
Chris LaFrancis
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Chris LaFrancis
Top achievements
Rank 1
Dimo
Telerik team
Matt DiPietro
Top achievements
Rank 1
Share this question
or