【问题标题】:Change datasource of Telerik RadGrid on DropDownList change event在 DropDownList 更改事件上更改 Telerik RadGrid 的数据源
【发布时间】:2023-04-10 11:22:16
【问题描述】:

我的页面上有 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(下拉列表):

<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();
}

【问题讨论】:

  • 你为什么不使用
  • @sakir 我也试过 但行为是一样的。

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


【解决方案1】:

我找到了解决方案。也许它会帮助某人。

我们必须在我们的 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。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    • 2023-04-05
    相关资源
    最近更新 更多