Pergunta

I tried to Filter an ASPxComboBox that gets data using an XpoDataSource, note that restoring and filtering data from a small data set works fine , the issue start when I try to filter large dataset - about 70000 records- from datasource the ComboBox loading becomes very slow since XpoDataSource gets all data from database table . So I created a criteria for the XpoDataSource to reduce number of records restored ,then the ComboBox Keeps repeating the top 10 records while scrolling down the ComboBox, I don't know where the problem is.

I realized that what I need is similar to the example in the following link

But using an XpoDataSource instead of SqlDataSource1 . I don't know how to write a similar code for an XpoDataSource .

this is my code :

protected void cmbServices_OnItemRequestedByValue_SQL(object source, DevExpress.Web.ASPxEditors.ListEditItemRequestedByValueEventArgs e)
    {
        try
        {
            string criteria = "";
            if (string.IsNullOrEmpty(e.Value.ToString()) || e.Value.ToString().Length < 3)
            {
                criteria = "1 = 2";
            }
            else
            {

                criteria =
                    string.Format("(( Code like '{0}%' OR ProductName like '{0}%') AND  CustomerId = {1})", e.Value.ToString(), (cmbServicesActivities != null && cmbServicesActivities.Value != null) ? cmbServicesActivities.Value.ToString() : "0");
            }
            dsServices.Session = LookupsSession;
            dsServices.Criteria = criteria;
            cmbServicesDescription.DataSource = dsServices;
            cmbServicesDescription.DataBind();
        }
        catch (Exception exc)
        {
            Debug.WriteLine(exc.Message);
        }
    }
Foi útil?

Solução

The Following Example demonstrates the answer of my question

public partial class _Default : System.Web.UI.Page {
Session session = XpoHelper.GetNewSession();

protected void cmb_ItemRequestedByValue(object source, DevExpress.Web.ASPxEditors.ListEditItemRequestedByValueEventArgs e) {
    MyObject obj = session.GetObjectByKey<MyObject>(e.Value);

    if (obj != null) {
        cmb.DataSource = new MyObject[] { obj };
        cmb.DataBindItems();
    }
}

protected void cmb_ItemsRequestedByFilterCondition(object source, DevExpress.Web.ASPxEditors.ListEditItemsRequestedByFilterConditionEventArgs e) {
    XPCollection<MyObject> collection = new XPCollection<MyObject>(session);
    collection.SkipReturnedObjects = e.BeginIndex;
    collection.TopReturnedObjects = e.EndIndex - e.BeginIndex + 1;
    collection.Criteria = new BinaryOperator("Title", String.Format("%{0}%", e.Filter), BinaryOperatorType.Like);
    collection.Sorting.Add(new SortProperty("Oid", DevExpress.Xpo.DB.SortingDirection.Ascending));

    cmb.DataSource = collection;
    cmb.DataBindItems();
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top