ARATHY
ARATHY

Reputation: 349

How to change a link button's text on grid view when clicks on it

I have grid view with link button named 'CLICK'. when clicks on this link button I wants to change its text to "CLICKED" I have done like this, on row command

if (e.CommandName == "ARCHIVE") //FOR SETTING THE VIEW LINK BUTTON
     {

             LinkButton lnkbtn = (LinkButton)sender;
            lnkbtn.Text = "viewed";
            lnkbtn.Enabled = false;


     }

but its not working. please help

Upvotes: 0

Views: 3016

Answers (5)

Suraj Singh
Suraj Singh

Reputation: 4069

 if (e.CommandName == "ARCHIVE")
            {
                LinkButton lnkbtn= (LinkButton)e.CommandSource;
                lnkbtn.Text = "Clicked";
                lnkbtn.Enabled = false;
            }

Upvotes: 0

Tadit Dash
Tadit Dash

Reputation: 305

if (e.CommandName == "ARCHIVE") //FOR SETTING THE VIEW LINK BUTTON
{
    GridViewRow row = (GridViewRow)((Control)e.CommandSource).NamingContainer;

    LinkButton lnkbtn = (LinkButton)row.FindControl("lnkClick"); // LinkButton ID
    lnkbtn.Text = "viewed";
    lnkbtn.Enabled = false;
}

Reference - How to get GridView's LinkButton ForeColor in RowCommand Event?

Upvotes: 0

Manu
Manu

Reputation: 418

Another way is:

if (e.CommandName == "ARCHIEVE")
    {
        LinkButton lnkButton = (LinkButton)e.CommandSource;
        if (lnkButton != null)

            if (lnkButton.Text.ToUpper() == "ARCHIEVE")
            {

                lnkButton.Text = "VIEWED";
            }

            else if (lnkButton.Text.ToUpper() == "VIEWED")
            {

                lnkButton.Text = "ARCHIEVE";
            }
    }

Upvotes: 1

Manu
Manu

Reputation: 418

Try this using javascript:

 OnClientClick="javascript:if (this.value=='Archieve') this.value = 'Viewed';else this.value = 'Bookmark';"></asp:LinkButton>

Upvotes: 1

Amit Singh
Amit Singh

Reputation: 8119

Try like this...

if (e.CommandName == "ARCHIVE") //FOR SETTING THE VIEW LINK BUTTON
     {

             LinkButton lnkbtn = (LinkButton)e.CommandSource;
            lnkbtn.Text = "viewed";
            lnkbtn.Enabled = false;


     }

Upvotes: 1

Related Questions