我的页面上有Telerik
RadGrid
和DropDownList
。我想从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();
}
答案 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。