I have a gridview with two check box columns. One is for selection and the other for setting a property something like "add to favorite". This gridview is loaded code behind and the check boxes are defined inside Item Template. The problem is that it is not very user friendly to have someone check two boxes for the same row, when they could have just selected "add to favorite" and this should automatically check the selection check box too. I understand this could be easily done using jquery as I do not think making a postback for these selections is a good user experience. I am very new to jquery and so any help would be appreciated.
The checkboxes on the same row follow the same convention for id, so if select is cbSelect_0, the other one will be cbfavorite_0. I also gave all the cbFavorite checkboxes the same class "cbMul" and then I wrote a function
function checkUncheck() {
$(".cbMul").checked(function() {
if ( $(this).attr('checked')) {
$('#myCheckbox').attr('checked', false);
} else {
$('#myCheckbox').attr('checked', 'checked');
}
}); }
Now, I do not understand how do I get the attributes of the checkbox that was checked, replace the the name and get the id of the checkbox if select and then check that one?
Here is the gridview:
<asp:GridView ID="gvEnvironments" EmptyDataText="--- No Data ---" runat="server" AutoGenerateColumns="false"
DataKeyNames="Id" >
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="cbSelectEnvironments" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Id" HeaderText="ID" InsertVisible="false" ReadOnly="true" SortExpression="Id" />
<asp:TemplateField HeaderText="Multi">
<ItemTemplate>
<asp:CheckBox ID="cbFav" runat="server" Checked="false" CssClass="cbMul" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Description" HeaderText="Description" HeaderStyle-Width="300px" SortExpression="Description" />
</Columns>