Click here to Skip to main content
15,848,930 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
sir, i have a gridview in which 2 columns are there. (1)- course,(2)-Sem . both are show using checkbox in gridview.
i need that when i select a particular course then the color of sem checkbox are change. how can i do it.

1 solution

Use jQuery:

$("#your_grid_id").on ("click", "input[type=checkbox]", function () {
if (this.checked)
    $(this).css("backgroud-color", "green");
    $(this).css("backgroud-color", "red");

The above code works like this:
Take your grid and to all checkboxes assign click handler. Click changes background colors to green and red depending on the checkstate.

You might need to tweak it a bit for your particular colors and other filters (you might want only particular checkboxes not all within the grid).

If you're doing server round-trip on checkbox click, you might simply do

if (yourCheckbox.Checked)
    yourCheckbox.BackColor = System.Drawing.Color.Green;
    yourCheckbox.BackColor = System.Drawing.Color.Red;

If this helps, please take time to accept the solution. Thank you.
Share this answer
TCS54321 18-Sep-14 8:51am    
there are 10 sem in 2nd column. i need that when i select a course only particular sem checkbox color will be change.

my gridview code is:-

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="100%"
CssClass="EU_DataTable" HeaderStyle-HorizontalAlign="Center"
HeaderStyle-Font-Bold="True" HeaderStyle-Height="32px" Font-Size="10pt" >

<asp:TemplateField Visible="False">
<asp:Label ID="lblCourseid" runat="server" Text='<%# Bind("Courseid") %>'>

<asp:TemplateField HeaderText="Course/Sem">
<asp:CheckBox ID="ChkIn" runat="server" AutoPostBack="true" OnCheckedChanged="Color"/>
<asp:Label ID="lblcourse" runat="server" Text='<%# Bind("Course") %>'>
<br />

<asp:TemplateField HeaderText="Sem" SortExpression="Sem">
<asp:CheckBoxList ID="chkSem" runat="server" DataSourceID="SqlSem"
DataTextField="Serial" DataValueField="Semid" RepeatColumns="5" RepeatDirection="Horizontal">

<HeaderStyle BackColor="Gray" ForeColor="White" HorizontalAlign="Left" />
TCS54321 18-Sep-14 8:53am    
for example:- if i select course that name then only 1,3 and 6 sem checkbox color will be change
Sinisa Hajnal 18-Sep-14 9:45am    
Did you try my code? Is there a problem with it? I understand what you want, the code above should cover both client side and server side (depending on what's easier for you) - since you have AutoPostBack= true and onCheckedChanged, go to your click handler (Color) and copy my code (change the variable name of course)

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