We can access the check box in grid control in client side using java script
Introduction
In This article we shall learn how
to restrict user to select multiple recipients.
Using
the code
We can access the check box in grid
control in client side using java script.
When there are two recipients groups
available to user to send messages to them .for Group 1 user will be allow to
send one recipient at a time , for Group 2 he will be allow to send multiple. For 2nd
case there is no need to write any JavaScript code because check boxes allow us
select multiple at a time.
For Group 1 we need to write below
java script code:
<script type="text/javascript" language="javascript">
function
checkboxClicked(event , idfrag)
{
var currentCheckBox = event.srcElement ||
event.target;
var inputs = document.getElementsByTagName("input");
for (var i = 0;
i < inputs.length; i++)
{
var input =
inputs[i];
if (input.id == currentCheckBox.id)
continue;
if (input.id.indexOf(idfrag) <
0)
continue;
//clear out the rest of the checkboxes
if (input.type && input.type == "checkbox")
{
input.checked = false;
}
}
}
</script>
.ASPX file::
<asp:GridView ID="grdRecipients" runat="server" DataKeyNames="id"
AutoGenerateColumns="False"
CellPadding="7"
GridLines="None"
Width="100%"
EmptyDataText="No
Recipients Available" HeaderStyle-BackColor="White" BackColor="#FBF9FC" AlternatingRowStyle-BackColor="#F0EAF6" >
<RowStyle />
<Columns>
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:CheckBox ID="chkAssign"
runat="server"
ToolTip='<%# Eval("id") %>' AutoPostBack="true"onclick="checkboxClicked(event,'chkAssign')"
/>
</ItemTemplate>
<ItemStyle
Width="25%"
/>
</asp:TemplateField>
</Columns>
<FooterStyle CssClass="display" />
<HeaderStyle BackColor="White"
CssClass="display"
/>
</asp:GridView>
Conclusion
Single Check box selection from a group of check boxes is a
very rare condition. If any other solution easier then this please respond to this article.