I am using Telerik grid in c#. This is my code for the grid columns.
<telerik:GridTemplateColumn HeaderText="Active" UniqueName="Active">
<ItemTemplate>
<asp:CheckBox ID="chbActive" runat="server"></asp:CheckBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Order" UniqueName="ORDER_FLAG">
<ItemTemplate>
<asp:CheckBox ID="chbORDER_FLAG" runat="server"></asp:CheckBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Sell" UniqueName="SELL_FLAG">
<ItemTemplate>
<asp:CheckBox ID="chbSELL_FLAG" runat="server"></asp:CheckBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Auto GRN" UniqueName="Auto_GRN">
<ItemTemplate>
<asp:CheckBox ID="ChkAutoGrn" runat="server"></asp:CheckBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
Now in this case whenever I checked 'Auto GRN' checkbox ,the 'Order' checkbox should unchecked automatically in grid and same condition for reverse scenario..
How I will achieve this..
Please check below demo.
.aspx
<telerik:RadGrid ID="RadGrid3" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid3_NeedDataSource"
OnItemDataBound="RadGrid3_ItemDataBound">
<MasterTableView>
<Columns>
<telerik:GridTemplateColumn>
<ItemTemplate>
<asp:CheckBox ID="Chk1" runat="server" />
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn>
<ItemTemplate>
<asp:CheckBox ID="Chk2" runat="server" />
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn HeaderText="ID" DataField="ID" UniqueName="ID">
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
.aspx.cs
protected void RadGrid3_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
dynamic data = new[] {
new { ID = 1, Name ="Name1"},
new { ID = 2, Name = "Name2"},
new { ID = 3, Name = "Name3"}
};
RadGrid3.DataSource = data;
}
protected void RadGrid3_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem item = e.Item as GridDataItem;
CheckBox Chk1 = item.FindControl("Chk1") as CheckBox;
CheckBox Chk2 = item.FindControl("Chk2") as CheckBox;
// default first check box will be checked
Chk1.Checked = true;
Chk1.Attributes.Add("onclick", "checkUncheckManage(this,'" + Chk2.ClientID+ "')");
Chk2.Attributes.Add("onclick", "checkUncheckManage(this,'" + Chk1.ClientID + "')");
}
}
JS
function checkUncheckManage(chkA, chkB) {
var _chkB = document.getElementById(chkB);
_chkB.checked = !chkA.checked;
}