rizzz86
rizzz86

Reputation: 3990

Change datasource of Telerik RadGrid on DropDownList change event

I have a Telerik RadGrid and DropDownList on my page. I want to change the datasource of RadGrid when any value is selected from DropDownList. I can able to execute all the pieces of code but datasource and data never changed. Following is the code:

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

All these methods get called and executed successfully but there is no impact on 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();
}

Upvotes: 0

Views: 969

Answers (1)

rizzz86
rizzz86

Reputation: 3990

I found the solution for this. May be it will help someone.

We have to add RadAjaxManager in our aspx:

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

This will update the RadGrid.

Upvotes: 2

Related Questions