DevExpress ASPxComboBox不进行过滤 [英] DevExpress ASPxComboBox not filtering

查看:900
本文介绍了DevExpress ASPxComboBox不进行过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个来自DevExpress套件的ASPxComboBox,我试图让它过滤。如果我点击组合框的下拉按钮,它会显示前几个查询,如果过滤器是空的。

I have an ASPxComboBox from the DevExpress suite and am trying to get it filtered. If I click on the dropdown button of the combo box it will show the first few of the query as if the filter is empty.

如果我尝试填充过滤器,或向下滚动以查看更多,它将只提供永久的加载状态。存储过程在使用适当的参数运行时返回正确的结果。可能是什么问题?

If I try to populate the filter, or scroll down to see more, it will just provide a perpetual "Loading" state. The stored procedure returns the correct results when ran with appropriate parameters. What could be the problem?

编辑:我一直在DevExpress网站上遵循本教程: http://demos.devexpress.com/ASPxEditorsDemos/ASPxComboBox/LargeDataSource.aspx

I have been following this tutorial on the DevExpress site: http://demos.devexpress.com/ASPxEditorsDemos/ASPxComboBox/LargeDataSource.aspx

编辑(再次):OK如果我删除了这一行:

EDIT (again): OK if I remove the line:

<ClientSideEvents BeginCallback="function(s, e) { OnBeginCallback(); }" EndCallback="function(s, e) { OnEndCallback(); } " />

从组合框中将在中打破断点cboInstructor_OnItemsRequestedByFilterCondition_SQL ,但是转到 DataBind()它会导致错误:

from the combo box it will hit a break point in cboInstructor_OnItemsRequestedByFilterCondition_SQL, but on going to the DataBind() it will thorw the error:


索引(基于零)必须大于
大于或等于零,小于
参数列表的大小。

Index (zero based) must be greater than or equal to zero and less than the size of the argument list.

ASP档案

<form id="form1" runat="server">
<div>
    <dxe:ASPxComboBox ID="cboInstructor" runat="server" Width="100%"
        EnableCallbackMode="True" CallbackPageSize="10"
        IncrementalFilteringMode="Contains" ValueType="System.Int32" ValueField="employee_id"
        OnItemsRequestedByFilterCondition="cboInstructor_OnItemsRequestedByFilterCondition_SQL"
        OnItemRequestedByValue="cboInstructor_OnItemRequestedByValue_SQL" TextFormatString="{1} {2}"
        DropDownStyle="DropDown" DataSourceID="SqlDataSourceInstruct"
    >
        <Columns>
            <dxe:ListBoxColumn FieldName="display_forename" />
            <dxe:ListBoxColumn FieldName="display_surname" />
        </Columns>
        <ClientSideEvents BeginCallback="function(s, e) { OnBeginCallback(); }" EndCallback="function(s, e) { OnEndCallback(); } " />
    </dxe:ASPxComboBox>
    <asp:SqlDataSource ID="SqlDataSourceInstruct" runat="server" ConnectionString="Server=160.10.1.25;User ID=root;Password=password;Persist Security Info=True;Database=central" ProviderName="MySql.Data.MySqlClient" SelectCommand="GetUser" SelectCommandType="StoredProcedure">
        <SelectParameters>
            <asp:Parameter Name="filter" Type="String" />
            <asp:Parameter Name="startIndex" Type="Int32" />
            <asp:Parameter Name="endIndex" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>
</div>
</form>

CS档案

public partial class TestComboBox : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void cboInstructor_OnItemsRequestedByFilterCondition_SQL(object source, ListEditItemsRequestedByFilterConditionEventArgs e)
    {
        ASPxComboBox comboBox = (ASPxComboBox)source;
        //SqlDataSourceInstruct.SelectCommand =
        //       @"SELECT CONCAT(display_Forename, ' ', display_Surname) FROM (SELECT employee_id, display_forename , display_surname, @rownum:=@rownum+1 AS rn FROM central.user_record, (SELECT @rownum:=0) AS r WHERE CONCAT(display_forename, ' ', display_surname) LIKE @filter ORDER BY display_surname ASC) AS st where st.rn between @startIndex and @endIndex";

        SqlDataSourceInstruct.SelectParameters.Clear();
        SqlDataSourceInstruct.SelectParameters.Add("filter", TypeCode.String, string.Format("%{0}%", e.Filter));
        SqlDataSourceInstruct.SelectParameters.Add("startIndex", TypeCode.Int64, (e.BeginIndex + 1).ToString());
        SqlDataSourceInstruct.SelectParameters.Add("endIndex", TypeCode.Int64, (e.EndIndex + 1).ToString());
        //comboBox.DataSource = SqlDataSourceInstruct;
        comboBox.DataBind();
    }

    protected void cboInstructor_OnItemRequestedByValue_SQL(object source, ListEditItemRequestedByValueEventArgs e)
    {
        long value = 0;
        if (e.Value == null)
            return;
        if (!Int64.TryParse(e.Value.ToString(), out value))
            return;
        ASPxComboBox comboBox = (ASPxComboBox)source;
        SqlDataSourceInstruct.SelectCommand = @"SELECT employee_id, display_surname, display_forename FROM central.user_record WHERE (employee_id = @ID) ORDER BY display_forename";

        SqlDataSourceInstruct.SelectParameters.Clear();
        SqlDataSourceInstruct.SelectParameters.Add("ID", TypeCode.Int64, e.Value.ToString());
        comboBox.DataSource = SqlDataSourceInstruct;
        comboBox.DataBind();

    }
}

MySQL存储过程

DELIMITER $$

USE `central`$$

DROP PROCEDURE IF EXISTS `GetUser`$$

CREATE DEFINER=`root`@`%` PROCEDURE `GetUser`(filter VARCHAR(50), startIndex INT, endIndex INT)
BEGIN
    SELECT employee_id, display_Forename, display_Surname
    FROM 
        (SELECT 
            employee_id
            , display_forename
            , display_surname
            , @rownum:=@rownum+1 AS rn  
        FROM central.user_record, 
            (SELECT @rownum:=0) AS r 
        WHERE CONCAT(display_forename, ' ', display_surname) LIKE filter
        ORDER BY display_surname ASC) AS st 
    WHERE st.rn BETWEEN startIndex AND endIndex;
    END$$

DELIMITER ;


推荐答案

为什么这些东西总是那么简单?我在 ASPxComboBox 中有 TextFormatString ={1} {2},并且只有2列删除它并忘记更改 TextFormatString 我也删除了 ClientSideEvents ,因为他们是从示例

Why are these things always so simple?! I had TextFormatString="{1} {2}" in the ASPxComboBox and there are only 2 columns, I had a third before but removed it and forgot to change the TextFormatString I also just removed the ClientSideEvents as they were from the example I posted above, but I wasn't using them.

一切正常!

这篇关于DevExpress ASPxComboBox不进行过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆