Link to home
Start Free TrialLog in
Avatar of ybt
ybt

asked on

How to change text on a link button dynamically

ASP.NET,  C#
I have a link button in a repeater:
 <th class="auto-style7">
                            <br /><br />
                          <asp:LinkButton ID="lnkreq_policy" runat="server" Text="Policy No" ForeColor="gray" OnClick="lnkreq_policy_click" >
                         
                       </asp:LinkButton>
                            </th>
to sort by this column, code behind:
protected void lnkreq_policy_click(object sender, EventArgs e)
        {
            ls_sort = "policy";
         
            f_sorting(ls_sort);
           

        }
how to change a link button text to: "asc Policy_no"
Avatar of Misha
Misha
Flag of Russian Federation image

If you want ro change text button you can put this small C# code:
lnkreq_policy.Text = "asc Policy_no";

Open in new window

If I correct understand you...
Avatar of ybt
ybt

ASKER

I tried this way, but this link button in a header of repeater and this did not compiled
Is there some errors after compilation? Can you post it here?
Also try to  remove
'EnableViewState = "False"

Open in new window

on your gridview.
Avatar of ybt

ASKER

This is not gridview, this is repeater, and error "The name 'lnkreq_policy' does not exist in the current context"
Ok, it this case try this code:

protected void lnkreq_policy_click(object sender, EventArgs e)
{
    LinkButton Yourbutton = sender as LinkButton;
    Yourbutton .Text = "asc Policy_no";
}

Open in new window

Avatar of ybt

ASKER

No error now, but text did not change
it's not clear....
May be this answer can help you:
https://www.experts-exchange.com/questions/23409860/asp-net-linkbutton-in-repeater-dynamically-create-linkbutton-text-field-value.html
Also you can try this approach:
You can handle the ItemDataBound event for your dataRepeater.
In the event handler you can check
e.Item.ItemType 

Open in new window

and if it is your Header you can
use code
 e.Item.FindControl("lnkreq_policy") 

Open in new window

to get a reference to the
LinkButton.
And then cahnge property Text..
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.