根据用户选择刷新RadGrid,无需刷新页面

时间:2014-01-27 19:13:42

标签: asp.net telerik radgrid radcombobox

在我的页面上,我有一个RadGrid(名为RadGrid1)和一个RadComboBox(名为Client)。两者都是从SQL数据库填充的,这就是我正在尝试做的事情;

当用户从下拉列表中选择客户端时,我想在重新加载页面时重新加载网格。这是网格和组合框

<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>

这是RadCmboBox的OnSelectedIndexChanged事件

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

最后是Load方法

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

任何人都对我在这里做错了什么有任何想法。我知道我可以在RadComboBox上将AutoPostBack设置为True,但我正在尝试阻止页面重新加载。

2 个答案:

答案 0 :(得分:1)

添加AutoPostBack = True完全符合我的要求,而不是我期待它做的事

答案 1 :(得分:0)

当您从列表中选择项目时,您可以使用telerik Ajax管理器仅重新加载网格,以避免页面的完整回发。