0

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;

Here , when i click the one of the command source , like name.. it changes the bg color 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

afzalulh
  • 7,925
  • 2
  • 26
  • 37

2 Answers2

0

Keep a hidden variable near to that button and set the value of that as "0" by default. Everytime 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

Shyju
  • 214,206
  • 104
  • 411
  • 497
0

Where you bind the gridview initially, set the background-color of the linkbutton, say as White. Do this by placing a foreach gridview row statement to assign the background color as such. Then use an IF-Else clause to check the current background color and switch accordingly.

if(objrow1.BackColor == Color.BurlyWood);
    objlink.BackColor = Color.White;
else 
    objrow1.BackColor = Color.BurlyWood;
Afzaal Ahmad Zeeshan
  • 15,669
  • 12
  • 55
  • 103