HOW TO USE LINKBUTTON IN GRIDVIEW USING C#

Madam Walker

Total Post:22

Points:154
Posted by  Madam Walker
C# 
C#
 1053  View(s)
Ratings:
Rate this:

I have a code like this

        GridViewRowCollection row1 = GridView2.Rows;
        foreach (GridViewRow row in GridView2.Rows)
        {
            LinkButton objlink = (LinkButton)row.FindControl("LinkButton2");
            objlink.ForeColor = Color.Blue;
        }
        LinkButton objrow1 = (LinkButton)(e.CommandSource);
        objrow1.BackColor = Color.BurlyWood;

When I click the one of the command source , like name.. it changes the bgcolor for that name ,but I also want to click one more time on same name to to disable bg color..

How can i achieve this?

Thanks in advanced!

  1. Ida B Wells

    Post:30

    Points:210
    Re: How to use Linkbutton in Gridview using C#

    Maintain a hidden variable near to that button and set the value of that as "0" by default. Every time you click on the adjacent button, Increase the value of this hidden variable. Now in the click event you can check the current value and decide whether you want to change the background color to Blue or Re or whatever color you want

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!