sharmila k

sharmila k

  • NA
  • 62
  • 51.7k

Javascript for gridview template field background color

Nov 5 2013 9:13 AM

Hi friend,

I have some sql data to display in grid view in button click.

Top of Form

S.No

 

Enquiry_id

Amount_paid

Payment_mode

sl_no

1

1

1000.0000

Check

1

2

2

500.0000

Check

2

3

5

1500.0000

Check

3

4

3

1500.0000

Check

1

5

4

1000.0000

Cash

2

Bottom of Form

 

In that grid view details,

If I want to selected particular row means, the selected row color will be changed using JavaScript.

Output

S.No

 

Enquiry_id

Amount_paid

Payment_mode

sl_no

1

1

1000.0000

Check

1

2

2

500.0000

Check

2

3

5

1500.0000

Check

3

4

3

1500.0000

Check

1

5

4

1000.0000

Cash

2

 

Code

                <script type="text/javascript">

         //variable that will store the id of the last clicked row

         var previousRow;

         function ChangeRowColor(row) {

             //If last clicked row and the current clicked row are same

             if (previousRow == row)

                 return; //do nothing

             //If there is row clicked earlier

             else if (previousRow != null)

             //change the color of the previous row back to white

                 document.getElementById(previousRow).style.backgroundColor = "#ffffff";                               

             //change the color of the current row to light yellow

             document.getElementById(row).style.backgroundColor = "#009ff8";

             //assign the current row id to the previous row id

             //for next row to be clicked

             previousRow = row;

         }

</script>

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

    {

        if (e.Row.RowType == DataControlRowType.DataRow)

        {

            e.Row.Attributes.Add("onclick", "javascript:ChangeRowColor('" + e.Row.ClientID + "')");

        }

 

    }

In that grid view I have using template field textbox. When I selected particular row I want to change template filed textbox background color also.

I try in Google search but I get result in grid view selected index changed code but I want JavaScript to implement.

Please anyone help me immediately.

Thanks in Advance.

 


Answers (3)