Click here to Skip to main content
15,924,402 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Frnds,

I want to change the background color of row when checkbox selected for particular row in asp.net gridview.



My requirement is from list of checkboxes user can select only one checkbox.....its work fine
This is my javascript to select only one checkbox, its working fine.

XML
<script type="text/javascript">
         function CheckSingleCheckbox(ob)
    {
        var grid = ob.parentNode.parentNode.parentNode;
        var inputs = grid.getElementsByTagName("input");
        for(var i=0;i<inputs.length;i++)
        {
            if (inputs[i].type =="checkbox")
            {
                if(ob.checked && inputs[i] != ob && inputs[i].checked)
                {
                    inputs[i].checked = false;
                }
            }
        }
    }

     </script>



Now I want to change the background of gridview row where checkbox is selected.

Please help thanks.
Posted
Comments
VICK 7-Oct-13 7:10am    
Have you tried using Gridview's "OnRowDataBound" event ????

Try below code
if(ob.checked){
       var tr = ob.parentNode.parentNode;
       tr.style.backgroundColor = "#FFFF66";
       }
 
Share this answer
 
See this code:
C#
foreach (GridViewRow row in GridView1.Rows)
{
   CheckBox chk = (CheckBox)row.Cells[0].FindControl("CheckBox1");
   if(chk.Checked)
       row.BackColor = System.Drawing.ColorTranslator.FromHtml("#000");  
}

I assumed the checkbox is in first cell of GridView. Put this code whenever you want to change background color of selected rows(for example,in button click).

Regards..
 
Share this answer
 
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900