Working with Telerik RadGrid

本文关键字:RadGrid Telerik with Working | 更新日期: 2023-09-27 18:15:50

我有一个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"。如果用户选择了Role,那么我们需要显示aspx页面中定义的grvRole

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

Working with Telerik RadGrid

任何构思好的东西都清楚地说出来,并且说出来的话流畅流畅

如何:显示/隐藏基于RadComboBox值的控件?

首先让我们声明一个简单的RadComboBox,包含3个inline Items:

<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/。我们现在需要一个事件,当用户每次选择一个"值"时触发。

OnSelectedIndexChanged将做的伎俩。
当你谈论jQuery实现时,这里是RadComboBox事件的文档:

    <
  • 服务器端事件/gh>客户端事件

注意: SelectedIndexChangedTextChangedOnCheckAllCheck事件不触发除非你设置AutoPostBack属性为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 == "担保"){{var masterTableView = sender.get_masterTableView();var columnIndex = masterTableView.getColumnByUniqueName(" Amount").get_element().cellIndex;masterTableView.showColumn (columnIndex);}}