Reylin Mathew

Reylin Mathew

  • NA
  • 347
  • 71.4k

select only multiple checkbox using inner grid.

Jul 13 2018 1:58 AM
radio button and checkbox are placed on inner grid. in my problem radio button is working but check box is not working, all the check box is select. i need atleast 2 check box is select using inner grid..  if more than 2 check box select  i want error is display...how can i solve this problem
 
 
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Vote.aspx.cs" Inherits="CollegeElection.Vote" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script language="javascript" type="text/javascript">
</script>
<script language="javascript" type="text/javascript">
function SelectSingleRadiobutton(rdBtnID) {
//process the radio button Being checked.
var rduser = $(document.getElementById(rdBtnID));
rduser.closest('TR').addClass('SelectedRowStyle');
rduser.checked = true;
//process all other radio buttons (excluding the the radio button Being checked).
var list = rduser.closest('table').find("INPUT[type='radio']").not(rduser);
list.attr('checked', false);
list.closest('TR').removeClass('SelectedRowStyle');
}
</script>
<script language="javascript" type="text/javascript">
function SelectAllCheckboxes(chk) {
$('#<%=gdPosition.ClientID %> >tbody >tr >td >input:checkbox').attr('checked', chk.checked);
}</script>
<style type="text/css">
.auto-style1 {
width: 104px;
}
.SelectedRowStyle
{
background-color: yellow;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<br />
<br />
<asp:Panel ID="pnlRegister" runat="server">
<center> <table border="1">
<tr>
<td class="auto-style1">REGISTER NO</td>
<td><asp:TextBox ID="txtRegisterNo" runat="server"></asp:TextBox></td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Enter Your Register Number" ControlToValidate="txtRegisterNo"></asp:RequiredFieldValidator>
</tr>
<tr><td class="auto-style1"> <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click1" Width="76px" />
<asp:Label ID="lblErr" runat="server"></asp:Label>
</td></tr>
</table></center>
</asp:Panel>
<asp:Panel ID="pnlElection" runat="server">
<center> <table border="1">
<tr>
<td>STUDENT NAME:</td>
<td><asp:Label ID="lblStdName" runat="server"></asp:Label></td>
</tr>
<tr>
<td>BATCH NAME:</td>
<td><asp:Label ID="lblbatch" runat="server"></asp:Label></td>
</tr>
</table>
</center>
<br />
<center>
<asp:GridView ID="gdPosition" runat="server" AutoGenerateColumns="False" DataKeyNames="Pid,Vote" OnRowDataBound="gdPosition_RowDataBound" style="width:300px" >
<Columns>
<asp:TemplateField >
<ItemTemplate>
<center> <asp:Label ID="lblPosition" runat="server" Text='<%# Eval("Vote") %>'>
</asp:Label></center>
<asp:HiddenField ID="hdfPosition" runat="server" />
<asp:GridView ID="gdElection" runat="server" AutoGenerateColumns="False" DataKeyNames="Pid" style="width:300px" OnRowDataBound="gdElection_RowDataBound" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<center><asp:Label ID="Label1" runat="server" Text='<%# Eval("StdName") %>'></asp:Label></center>
<asp:Label id="hdfposition" runat="server" ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Vote For">
<ItemTemplate>
<%--- onclick="singleRbtnSelect(this);"---%>
<center>
<asp:RadioButton id="rdVote" runat="server" GroupName="Position" OnClick="javascript:SelectSingleRadiobutton(this.id)" />
<asp:label ID="lblpid" runat="server" Text='<%# Eval("Position") %>' Visible="false"></asp:label>
<asp:CheckBox id="chkvote" runat="server" visible="false" onclick="javascript:SelectAllCheckboxes(this);"></asp:CheckBox>
<%-- onclick="javascript:SelectheaderCheckboxes(header.id)" --%>
</center>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</center>
<br />
<center>
<asp:Button ID="btnVote" runat="server" Text="Vote" OnClick="btnVote_Click" ValidationGroup="GroupA" />
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Please select your candidate." ClientValidationFunction="ValidateRadioButton" ValidationGroup="GroupA" style="display:none"></asp:CustomValidator>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ValidationGroup="GroupA" HeaderText="" DisplayMode="BulletList" ForeColor="Red" />
<asp:Label ID="lblError" runat="server"></asp:Label></center>
</asp:Panel>
</div>
</form>
</body>
</html>