c# - DevExpress ASPxComboBox 不过滤

标签 c# asp.net mysql combobox devexpress

我有一个来自 DevExpress 套件的 ASPxComboBox,我正在尝试对其进行过滤。如果我单击组合框的下拉按钮,它将显示查询的前几个,就好像过滤器为空一样。

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

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

编辑(再次):好的,如果我删除该行:

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

从组合框中,它将在 cboInstructor_OnItemsRequestedByFilterCondition_SQL 中遇到断点,但在转到 DataBind() 时,它将抛出错误:

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,因为它们来 self 上面发布的示例,但我没有使用它们。

现在一切正常!

关于c# - DevExpress ASPxComboBox 不过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6305270/

相关文章:

c# - 使用 Task.Run 时避免捕获当前执行上下文

asp.net - 可能会导致 Postgres 异常 : 42501: must be a member of the role whose process is being terminated or member of pg_signal_backend?

php - 在 PHP/MySQL 中更新关系数据库

mysql - SQL按一组获取用户并增量位置

c# - 参数异常 "parameter is incorrect"

c# - asp MVC 中应该使用多少 JavaScript 代码?

c# - C# 到 C++/CLI 转换的陷阱

asp.net - 问题: zip files in mvc

asp.net - 使用 ajax/jquery 的未知 Web 方法

php - 如何使用周数来选择唯一记录ID的MYSQL PHP