Telerik RadGrid未被ComboBox过滤

时间:2014-08-08 14:31:48

标签: asp.net .net telerik telerik-grid

当ComboBox的选择发生变化时,我有一个可以过滤的网格:

<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>

<telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
<telerik:RadFormDecorator ID="QsfFromDecorator" runat="server" DecoratedControls="All" EnableRoundedCorners="false" />

<label for="NamesDDL">Select plant name to view its reports:</label>
<div style="margin-top: 15px;">
    <telerik:RadComboBox ID="NamesDDL" runat="server" AutoPostBack="True" DataSourceID="dllDataSource"
        DataTextField="PlantNameAndID" DataValueField="PlantID" Width="250px" Height="150px"
        AppendDataBoundItems="true" >
        <Items>
            <telerik:RadComboBoxItem Text="All" Value="0" Selected="true"></telerik:RadComboBoxItem>
        </Items>
    </telerik:RadComboBox>
</div>

<div style="margin: 15px 0 20px;">
    <telerik:RadGrid ID="OrdersGrid" AllowPaging="true" DataSourceID="gridSource" runat="server"
        GridLines="None" AllowSorting="true" HeaderStyle-ForeColor="Black" HeaderStyle-HorizontalAlign="Center">
    </telerik:RadGrid>
</div>

<asp:SqlDataSource ID="dllDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:Dev-TestOilConnectionString %>"
    SelectCommand="select customer.plant.PlantID, customer.plant.PlantNo, customer.plant.PlantName, customer.plant.PlantID, cast(customer.plant.PlantID as varchar) + ' - ' + customer.plant.PlantName as PlantNameAndID from customer.plant where plant.CustID = 10 order by plant.PlantNo"></asp:SqlDataSource>

<asp:SqlDataSource ID="gridSource" runat="server" ConnectionString="<%$ ConnectionStrings:Dev-TestOilConnectionString %>"
    SelectCommand="select LabID, SampleDate, MachCond, LubCond, CustReview, CustReviewDte, machine.PlantID from customer.plant inner join customer.machine on machine.PlantID = plant.PlantID inner join sample.sample on sample.PointID = machine.PointID where ((machine.PlantID = @PlantID and @PlantID <> 0) or (machine.PlantID = machine.PlantID and @PlantID = 0)) and plant.custid = 10">
    <SelectParameters>
        <asp:ControlParameter Name="PlantID" PropertyName="SelectedValue" ControlID="NamesDDL"></asp:ControlParameter>
    </SelectParameters>
</asp:SqlDataSource>

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" EnableAJAX="true" DefaultLoadingPanelID="RadAjaxLoadingPanel1">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="NamesDDL">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="OrdersGrid" LoadingPanelID="AjaxLoadingPanel1"></telerik:AjaxUpdatedControl>
                <telerik:AjaxUpdatedControl ControlID="NamesDDL"></telerik:AjaxUpdatedControl>
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>

<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
</telerik:RadAjaxLoadingPanel>

数据绑定最初工作正常,网格显示未过滤的所有记录。当我更改ComboBox中的选择时,网格会重新加载,但不会过滤数据。关于为什么这不起作用的任何想法?或者我如何采取不同的方法?

谢谢!

1 个答案:

答案 0 :(得分:0)

大部分对我来说都很好看。也许尝试将customer.plant.PlantID的别名作为PlantID。此外,您的dllDataSource中有两次相同的列。

这样的事情:

SelectCommand="select customer.plant.PlantID as PlantID, customer.plant.PlantNo, customer.plant.PlantName, cast(customer.plant.PlantID as varchar) + ' - ' + customer.plant.PlantName as PlantNameAndID from customer.plant where plant.CustID = 10 order by plant.PlantNo"></asp:SqlDataSource>