Question

On my page I have a RadGrid (named RadGrid1) and a RadComboBox (named Client). Both are being populated from a SQL database and here's what I'm attempting to do;

When the user selects a client from the dropdown list I want to reload the grid witout reloading the page. Here's the grid and combobox

<div style="vertical-align: top">
    <fieldset>
        <p>
            <asp:Label ID="ClientLabel" runat="server" AssociatedControlID="Client">Client</asp:Label><telerik:RadComboBox
                ID="Client" runat="server" ValidationGroup="GetRFPIDValidationGroup" OnSelectedIndexChanged="Client_SelectedIndexChanged" />
                <p>
                <asp:RequiredFieldValidator ID="ClientRequiredValidator" runat="server" ControlToValidate="Client"
                    CssClass="failureNotification" ErrorMessage="Client is required." ToolTip="Client is required."
                    ValidationGroup="GetRFPIDValidationGroup">*</asp:RequiredFieldValidator>
            </p>
            <p>
                &nbsp;<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" UpdateInitiatorPanelsOnly="True">
                    <AjaxSettings>
                        <telerik:AjaxSetting AjaxControlID="RadGrid1">
                            <UpdatedControls>
                                <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                                <telerik:AjaxUpdatedControl ControlID="Client" LoadingPanelID="RadAjaxLoadingPanel1" />
                            </UpdatedControls>
                        </telerik:AjaxSetting>
                        <telerik:AjaxSetting AjaxControlID="Client">
                            <UpdatedControls>
                                <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                            </UpdatedControls>
                        </telerik:AjaxSetting>
                    </AjaxSettings>
                </telerik:RadAjaxManager>
                <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
                </telerik:RadAjaxLoadingPanel>
                <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" LoadingPanelID="RadAjaxLoadingPanel1">
                    <telerik:RadGrid ID="RadGrid1" runat="server" AllowSorting="True" AllowPaging="True"
                        OnNeedDataSource="RadGrid1_NeedDataSource" OnSortCommand="RadGrid1_SortCommand">
                        <MasterTableView AllowMultiColumnSorting="true">
                            <PagerStyle AlwaysVisible="true" />
                        </MasterTableView>      
                    </telerik:RadGrid>
                </telerik:RadAjaxPanel>
            </p>
    </fieldset>
</div>

Here's the OnSelectedIndexChanged event of the RadCmboBox

Protected Sub Client_SelectedIndexChanged(sender As Object, e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs) Handles Client.SelectedIndexChanged
    RadGrid1.DataSource = Load(Client.SelectedItem.Text, "2014")
    RadGrid1.Rebind()
    Me.RadGrid1.MasterTableView.Rebind()
End Sub

And finally the Load method

Protected Sub RadGrid1_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
    TryCast(sender, RadGrid).DataSource = Load(Client.SelectedItem.Text, "2014")
End Sub

Public Function Load(ByVal client_id As String, ByVal year As String) As DataTable
    Using conn As New SqlConnection(SqlConn.GetConnectionString("ProLodgic"))
        Using cmd As New SqlCommand()
            With cmd
                .CommandType = CommandType.StoredProcedure
                .CommandText = "spLoadRFPIDs"
                .Parameters.AddWithValue("@ClientID", client_id)
                .Parameters.AddWithValue("@BidYear", year)
                .Connection = conn
            End With

            SqlConn.HandleConnection(conn, False)

            Using ad As New SqlDataAdapter(cmd)
                'ad.SelectCommand = cmd
                Dim table As New DataTable()
                Try

                    ad.Fill(table)
                    Return table
                Catch ex As Exception
                    ErrorMessage.Text = ex.Message
                    Return Nothing
                End Try
            End Using
        End Using
    End Using
End Function

Anyone got any ideas on what I'm doing wrong here. I know I can seet AutoPostBack to True on the RadComboBox but I'm trying to prevent a page reload.

Was it helpful?

Solution

Adding the AutoPostBack = True did exactly what I was looking for, not what I was expecting it to do

OTHER TIPS

You can use the telerik Ajax manager to reload only the grid when you select an item from the list , to avoid a full postback of the page.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top