0

我在 C# 中使用 Telerik 网格。这是我的网格列代码。

  <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>

现在在这种情况下,每当我选中“自动 GRN”复选框时,“订单”复选框应该在网格中自动取消选中,并且反向 senario 的条件相同。

我将如何实现这一目标..

4

1 回答 1

1

请查看下面的演示。

.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;
        }
于 2012-07-18T10:18:39.900 回答