使用 Telerik RadGrid

Working with Telerik RadGrid

我有一个 Rad 组合框和一个 2 个 RadGrids - grvUser 和 grvRole

grvUser RadGrid如下...

<telerik:RadGrid ID="grvUser" runat="server" EnableEmbeddedSkins="False"  Skin="skn_RadGrid" SkinsDir="|CurrentTheme|/" SkinsPath="|CurrentTheme|/"
            OnItemCreated="grvUser_ItemCreated" OnItemCommand="grvUser_ItemCommand" OnItemDataBound="grvUser_ItemDataBound" OnNeedDataSource="grvUser_NeedDataSource" GroupHeaderItemStyle-CssClass="rgGroupPanel">
            <MasterTableView TableLayout="Fixed" OverrideDataSourceControlSorting="true" NoMasterRecordsText ="No Records Found, Please Refine Search To Display "> 
                <Columns>
                    <telerik:GridBoundColumn FilterControlAltText="Filter column column" DataField="UserId"
                        UniqueName="UserId" HeaderText="User Id" HeaderStyle-Width="120px" FilterControlWidth="70px"
                        AutoPostBackOnFilter="true">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn FilterControlAltText="Filter column column" DataField="UserName" AllowFiltering="true" ShowFilterIcon="true"
                        UniqueName="UserName" HeaderText="User Name" HeaderStyle-Width="120px" FilterControlWidth="70px"
                        AutoPostBackOnFilter="true">
                    </telerik:GridBoundColumn>
                </Columns>
            </MasterTableView>
            </telerik:RadGrid>

grvRole RadGrid如下...

<telerik:RadGrid ID="grvRole" runat="server" EnableEmbeddedSkins="False"  Skin="skn_RadGrid" SkinsDir="|CurrentTheme|/" SkinsPath="|CurrentTheme|/"
            OnItemCreated="grvRole_ItemCreated" OnItemCommand="grvRole_ItemCommand" OnItemDataBound="grvRole_ItemDataBound" OnNeedDataSource="grvRole_NeedDataSource" GroupHeaderItemStyle-CssClass="rgGroupPanel">
            <MasterTableView TableLayout="Fixed" OverrideDataSourceControlSorting="true" NoMasterRecordsText ="No Records Found, Please Refine Search To Display "> 
                <Columns>
                    <telerik:GridBoundColumn FilterControlAltText="Filter column column" DataField="RoleId"
                        UniqueName="RoleId" HeaderText="Role Id" HeaderStyle-Width="120px" FilterControlWidth="70px"
                        AutoPostBackOnFilter="true">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn FilterControlAltText="Filter column column" DataField="RoleName" AllowFiltering="true" ShowFilterIcon="true"
                        UniqueName="RoleName" HeaderText="Role Name" HeaderStyle-Width="120px" FilterControlWidth="70px"
                        AutoPostBackOnFilter="true">
                    </telerik:GridBoundColumn>
                </Columns>
             </MasterTableView>
            </telerik:RadGrid>

RadComboBox的代码如下...

<telerik:RadComboBox ID="ddlType" runat="server" DataValueField="Description"
                        DataTextField="Description" Text="(Select)" AllowCustomText="True" Width="200px"
                        OnClientDropDownClosed="onDropDownClosing1"  Skin="Default">
                        <ItemTemplate>
                            <div onclick="StopPropagation(event)" class="combo-item-template" onmousemove="">
                                <asp:CheckBox runat="server" ID="chk1" onclick="onStatusChecked(this)" />
                                <asp:Label runat="server" ID="Label1" AssociatedControlID="chk1">
                              <%# Eval("Description")%>
                                </asp:Label>
                            </div>
                        </ItemTemplate>
                        <HeaderTemplate>
                            <asp:CheckBox ID="ChckAll" Text="(Check All)" runat="server" OnClick="checkAllStatus(this)" />
                        </HeaderTemplate>
                    </telerik:RadComboBox>

ddlType RadComboBox 包含 2 个值。 1 是用户,2 是角色。默认情况下 "User" 被选中,因此 grvUser 将被显示。如果用户选择角色,那么我们需要显示在aspx页面中定义的grvRole

我如何触发 RadComboBox 的 onchange 事件并显示正确的 RadGrid 用户或角色?

更新

jQuery 中的实现对我来说没问题。

Whatever is well conceived is clearly said, And the words to say it flow with ease.

如何:根据 RadComboBox 值显示/隐藏控件?

首先让我们声明一个简单的 RadComboBox,其中包含 3 个内联项:

<telerik:RadComboBox ID="RadComboBox1" runat="server" >
    <Items>   
        <telerik:RadComboBoxItem runat="server" Text="ALL" />   
        <telerik:RadComboBoxItem runat="server" Text="grvUser" />   
        <telerik:RadComboBoxItem runat="server" Text="grvRole" /> 
    </Items>
</telerik:RadComboBox>


1/。我们现在需要一个每次用户选择 "Value".

时都会触发的事件

OnSelectedIndexChanged 会成功的。
当您谈论 jQuery 实现时,这里是文档 RadComboBox 事件:

NOTE: The SelectedIndexChanged , TextChanged and OnCheckAllCheck events do not fire unless you set the AutoPostBack property to True .


2/.添加正确的事件和一些标签。

<telerik:RadComboBox ID="RadComboBox1" runat="server" autopostback="True"
                     OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged"  >
    <Items>   
        <telerik:RadComboBoxItem runat="server" Text="ALL" />   
        <telerik:RadComboBoxItem runat="server" Text="grvUser" />   
        <telerik:RadComboBoxItem runat="server" Text="grvRole" /> 
    </Items>
</telerik:RadComboBox>
<asp:Label ID="Label1" runat="server" Text="My Control 1(grvUser)" />
<asp:Label ID="Label2" runat="server" Text="My Control 2(grvRole)" />


3/。让我们将它们隐藏在代码后面

protected void RadComboBox1_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
    if (e.Text=="ALL")
    { 
        Label1.Visible = true; 
        Label2.Visible = true; 
    }
    else if (e.Text == "grvUser")            
    {
        Label1.Visible=true; 
        Label2.Visible=false;
    }
    else if (e.Text == "grvRole")
    { 
        Label1.Visible = false; 
        Label2.Visible = true; 
    }
}

那是一个客户端解决方案。

用这个来显示字段- var agtype = $telerik.$(atCell).text().trim();

if(agtype == ""Guaranty""){{ var masterTableView = sender.get_masterTableView(); var columnIndex = masterTableView.getColumnByUniqueName(""Amount"").get_element().cellIndex; masterTableView.showColumn(列索引); }}