在DropDownList更改事件上更改Telerik RadGrid的数据源

时间:2014-06-11 05:25:10

标签: asp.net drop-down-menu telerik radgrid

我的页面上有Telerik RadGridDropDownList。我想从DropDownList中选择任何值时更改RadGrid的数据源。我能够执行所有代码,但数据源和数据永远不会改变。以下是代码:

ASPX(RadGrid):

<telerik:RadGrid ID="exceptionList" runat="server" OnNeedDataSource="exceptionList_NeedDataSource"  AutoGenerateColumns="False" PageSize="10" EnableEmbeddedSkins="False"  AllowPaging = "True" AllowSorting = "True" GridLines="None"
 PagerStyle-AlwaysVisible="true" AllowCustomPaging="true" 
 Width="100%">

ASPX(DropDownList):

<asp:DropDownList id="FormCode"  runat="server" CssClass="cmb" style="width:98%;" OnSelectedIndexChanged="FormCode_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList>

ASPX.CS

所有这些方法都被成功调用并执行,但对RadGrid没有影响。

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        LoadComboBox(...);
        FormCode.Items[0].Text = "Select an item";
    }
}

protected void exceptionList_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
    DataView gridData = InitData(...);
    exceptionList.DataSource = gridData;
    exceptionList.PageSize = 50;
}

protected void FormCode_SelectedIndexChanged(object sender, EventArgs e)
{
    DataView gridData = ChangeData(...);
    exceptionList.DataSource = gridData;
    exceptionList.DataBind();
}

1 个答案:

答案 0 :(得分:2)

我找到了解决方法。可能会帮助别人。

我们必须在我们的aspx中添加RadAjaxManager:

    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="FormCode">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="exceptionList" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>

这将更新RadGrid。