Click here to Skip to main content
15,886,362 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.
Posted

1 solution

Use jQuery:

JavaScript
$("#your_grid_id").on ("click", "input[type=checkbox]", function () {
if (this.checked)
    $(this).css("backgroud-color", "green");
else
    $(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

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




If this helps, please take time to accept the solution. Thank you.
 
Share this answer
 
v2
Comments
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" >
<columns>


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



<asp:TemplateField HeaderText="Course/Sem">
<itemtemplate>
<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">
<itemtemplate>
<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 b.tech(csc) 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