如何在单击时更改网格视图上的链接按钮文本

时间:2013-10-03 09:33:40

标签: c# asp.net gridview

我的网格视图带有名为“CLICK”的链接按钮。当点击这个链接按钮时我想将其文本更改为“点击”我就像这样,在行命令上

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

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


     }

但它不起作用。请帮忙

5 个答案:

答案 0 :(得分:1)

试试这个......

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

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


     }

答案 1 :(得分:1)

尝试使用javascript:

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

答案 2 :(得分:1)

另一种方式是:

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";
            }
    }

答案 3 :(得分:0)

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;
}

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

答案 4 :(得分:0)

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