Click here to Skip to main content
15,904,828 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: iTextsharp vs pdfbox Pin
gavindon28-Apr-11 8:34
gavindon28-Apr-11 8:34 
GeneralRe: iTextsharp vs pdfbox Pin
Pete O'Hanlon28-Apr-11 8:36
mvePete O'Hanlon28-Apr-11 8:36 
QuestionUnable To Create Excel Sheet At Runtime In my Application. Pin
Sanket.Patil28-Apr-11 2:37
Sanket.Patil28-Apr-11 2:37 
AnswerRe: Unable To Create Excel Sheet At Runtime In my Application. Pin
Prasanta_Prince28-Apr-11 3:02
Prasanta_Prince28-Apr-11 3:02 
QuestionScorm content viewer Pin
nachavle27-Apr-11 23:05
nachavle27-Apr-11 23:05 
QuestionProblem with cascading DropDownLists in a databound DetailsView Pin
kbalias27-Apr-11 21:30
kbalias27-Apr-11 21:30 
AnswerRe: Problem with cascading DropDownLists in a databound DetailsView Pin
Ali Al Omairi(Abu AlHassan)28-Apr-11 0:45
professionalAli Al Omairi(Abu AlHassan)28-Apr-11 0:45 
QuestionObjectDataSource for DevExpress ASPxGtridView with enabled paging, sorting, grouping, external filters Pin
trongood27-Apr-11 21:15
trongood27-Apr-11 21:15 
The class is described below allows the use of grouping, sorting, pagind, external filters with DevExpress ASPxGridView, but using data access method as standart ASP.NET ObjectDataSource

Initialization of data binding in ASPxGridView looks like this:
protected override void OnInit(EventArgs e)
{
    base.OnInit(e);

    if (!IsPostBack)
    {
        DXExtensions.Data.DXObjectDataSource dxOdsAddress = new DXExtensions.Data.DXObjectDataSource();
        dxOdsAddress.PageSize = gvAddress.SettingsPager.PageSize;
        dxOdsAddress.KeyFeildName = gvAddress.KeyFieldName;
        dxOdsAddress.DataType = typeof(DomainModel.AddressEntities.Address);
        dxOdsAddress.Request_DataSource += new EventHandler<DXExtensions.Data.DXObjectDataSource.PagingEventArgs>(dxodsAddress_RequestDataSource);
        dxOdsAddress.Request_TotalRowsCount += new EventHandler(dxodsAddress_RequestTotalRowsCount);
        dxOdsAddress.Request_GroupInfo += new EventHandler<DXExtensions.Data.DXObjectDataSource.GroupingEventArgs>(dxodsAddress_RequestGroupInfo);
        Session["dxOdsAddress"] = dxOdsAddress;        
    }

    gvAddress.DataSource = Session["dxOdsAddress"] as DXExtensions.Data.DXObjectDataSource;
}

This class is based on the example described here: A possible implementation of IListServer interface to achieve Server Mode functionality
DXObjectDataSource class:
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using DevExpress.Data;

namespace DXExtensions.Data
{
    public class DXObjectDataSource : IListServer, ITypedList
    {
        #region New
                
        #region Exceptions

        public class DataSourceNotBindedException : Exception
        {
            public DataSourceNotBindedException()
                : base()
            {}
        }

        public class DataSourceSubcriberNotFoundException : Exception
        {
            public DataSourceSubcriberNotFoundException()
                : base()
            { }
        }

        public class TotalRowsCountNotBindedException : Exception 
        {
            public TotalRowsCountNotBindedException()
                : base()
            { }
        }

        public class TotalRowsCountSubscriberNotFoundException : Exception
        {
            public TotalRowsCountSubscriberNotFoundException()
                : base()
            { }
        }

        public class UnexpectedLogicWayException : Exception
        {
            public UnexpectedLogicWayException()
                : base()
            { }
        }

        #endregion

        #region PublicConnectors

        /// &lt;summary&gt;
        /// For paging with sorting
        /// &lt;/summary&gt;
        public class PagingEventArgs : EventArgs
        {
            private int _StartRowIndex;
            public int StartRowIndex
            {
                get
                {
                    return _StartRowIndex;
                }
                set
                {
                    _StartRowIndex = value;
                }
            }

            private int _RowsCount;
            public int RowsCount
            {
                get
                {
                    return _RowsCount;
                }
                set
                {
                    _RowsCount = value;
                }
            }

            private ICollection&lt;ServerModeOrderDescriptor&gt; _SortInfo;
            public ICollection&lt;ServerModeOrderDescriptor&gt; SortInfo
            {
                get
                {
                    return _SortInfo;
                }
                set
                {
                    _SortInfo = value;
                }
            }
        }

        /// &lt;summary&gt;
        /// For grouping with pagind and sorting
        /// &lt;/summary&gt;
        public class GroupingEventArgs : EventArgs
        {
            ListSourceGroupInfo _ParentGroupInfo;
            public ListSourceGroupInfo ParentGroupInfo
            {
                get
                {
                    return _ParentGroupInfo;
                }
                set
                {
                    _ParentGroupInfo = value;
                }
            }

            List&lt;ListSourceGroupInfo&gt; _GroupInfo;

            public List&lt;ListSourceGroupInfo&gt; GroupInfo
            {
                get
                {
                    return _GroupInfo;
                }
                set
                {
                    _GroupInfo = value;
                }
            }
        }

        /// &lt;summary&gt;
        /// Fires when data source needs a specific page from the database
        /// &lt;/summary&gt;
        public event EventHandler&lt;PagingEventArgs&gt; Request_DataSource;

        /// &lt;summary&gt;
        /// Fires when data source needs the number of rows using external filters
        /// &lt;/summary&gt;
        public event EventHandler Request_TotalRowsCount;

        /// &lt;summary&gt;
        /// Fires when data source needs group info
        /// &lt;/summary&gt;
        public event EventHandler&lt;GroupingEventArgs&gt; Request_GroupInfo;

        /// &lt;summary&gt;
        /// Used when external filters changed
        /// &lt;/summary&gt;
        public void RefreshForNewFilters()
        {
            _ActualizeDataSource_StartIndex = 0;
            _DataSource = null;
        } //надо избавиться от этого метода, но это проблематично пока используем внешние фильтры

        #endregion

        #region Propertyes
        
        private Type _DataType;
        /// &lt;summary&gt;
        /// The data type must be defined before binding
        /// &lt;/summary&gt;
        public Type DataType
        {
            get
            {
                return _DataType;
            }
            set
            {
                _DataType = value;
            }
        }

        private IList _DataSource;
        /// &lt;summary&gt;
        /// Stores range of rows
        /// &lt;/summary&gt;
        public IList DataSource
        {
            get
            {
                return _DataSource;
            }
            set
            {
                _DataSource = value;
            }
        }

        private Int32 _TotalRowsCount = -1;
        public Int32 TotalRowsCount
        {
            get
            {
                return _TotalRowsCount;
            }
            set
            {
                _TotalRowsCount = value;
            }
        }

        private Int32 _PageSize;
        /// &lt;summary&gt;
        /// The page size must be defined before binding
        /// &lt;/summary&gt;
        public Int32 PageSize
        {
            get
            {
                return _PageSize;
            }
            set
            {
                _PageSize = value;
            }
        }
        
        private string _KeyFeildName;
        /// &lt;summary&gt;
        /// The key field name must be defined before binding
        /// &lt;/summary&gt;
        public string KeyFeildName
        {
            get
            {
                return _KeyFeildName;
            }
            set
            {
                _KeyFeildName = value;
            }
        }

        /// &lt;summary&gt;
        /// Stores the previous collection sorting
        /// Need to understand that sort has changed
        /// &lt;/summary&gt;
        private ICollection&lt;ServerModeOrderDescriptor&gt; _SortInfo;

        #endregion

        /// &lt;summary&gt;
        /// Required not to send a query to the first page when it is not necessary
        /// &lt;/summary&gt;
        bool IsZeroIndexActual;

        /// &lt;summary&gt;
        /// Start row index for stored rows range
        /// &lt;/summary&gt;
        private int _ActualizeDataSource_StartIndex;

        /// &lt;summary&gt;
        /// Checks stored rows range and if necessary request a new range of rows from database using Request_DataSource event
        /// &lt;/summary&gt;
        /// &lt;param name="index"&gt;row index&lt;/param&gt;
        /// &lt;returns&gt;page size row index, not table row index&lt;/returns&gt;
        protected int ActualizeDataSource(int index)
        {
            bool isDataSourceActual = true;
            if (_DataSource == null)
            {                
                isDataSourceActual = false;                
            }
            else
            {
                if ((index == 0) &amp;&amp; (!IsZeroIndexActual))
                {
                    return 0;
                }
                else
                {
                    if ((index &gt;= _ActualizeDataSource_StartIndex + _PageSize) || ((index &lt; _ActualizeDataSource_StartIndex)))
                    {
                        isDataSourceActual = false;
                    }
                }
            }

            if (!isDataSourceActual)
            {
                _ActualizeDataSource_StartIndex = index;

                PagingEventArgs pea = new PagingEventArgs();
                pea.StartRowIndex = index;
                pea.RowsCount = _PageSize;
                pea.SortInfo = _SortInfo;                

                if (Request_DataSource != null)
                {
                    Request_DataSource(this, pea);
                    if (_DataSource == null)
                    {
                        throw new DataSourceNotBindedException();
                    }
                }
                else
                {
                    throw new DataSourceSubcriberNotFoundException();
                }
            }
            int ret = index - _ActualizeDataSource_StartIndex;
            if (ret &lt; 0)
            {
                ret = 0;
            }
            return ret;
        }

        #endregion

        #region IList Enabled

        object IList.this[int index]
        {
            get
            {
                int actualRecordIndex = ActualizeDataSource(index);

                if (_DataSource != null)
                {
                    return _DataSource[actualRecordIndex];
                }
                return null;
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        #endregion

        #region ICollection Enabled

        int ICollection.Count
        {
            get
            {
                return _TotalRowsCount;
            }
        }

        #endregion

        #region ITypedList Enabled

        PropertyDescriptorCollection ITypedList.GetItemProperties(PropertyDescriptor[] listAccessors)
        {
            IsZeroIndexActual = false; //true in Aplly

            PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(_DataType);

            if (Request_TotalRowsCount != null)
            {
                Request_TotalRowsCount(this, new EventArgs());
                if (_TotalRowsCount &lt; 0)
                {
                    throw new TotalRowsCountNotBindedException();
                }
            }
            else
            {
                throw new TotalRowsCountSubscriberNotFoundException();
            }
            return pdc;
        }

        #endregion

        #region DevExpress.Data.IListServer Enabled

        void IListServer.Apply
            (
                DevExpress.Data.Filtering.CriteriaOperator filterCriteria,
                ICollection&lt;ServerModeOrderDescriptor&gt; sortInfo,
                int groupCount,
                ICollection&lt;ServerModeSummaryDescriptor&gt; groupSummaryInfo,
                ICollection&lt;ServerModeSummaryDescriptor&gt; totalSummaryInfo
            )
        {
            if ((_SortInfo != sortInfo)) //new sort collection
            {
                _ActualizeDataSource_StartIndex = 0;
                _DataSource = null;
                _SortInfo = sortInfo;
            }

            IsZeroIndexActual = true; //Now when you request the index 0 should search the data for the first page
        }

        object IListServer.GetRowKey(int index)
        {
            int actualRecordIndex = ActualizeDataSource(index);
                        
            if (_DataSource != null)
            {
                System.Reflection.PropertyInfo pi = _DataType.GetProperty(KeyFeildName);
                System.Reflection.MethodInfo mi = pi.GetGetMethod();
                object recordObject = _DataSource[actualRecordIndex];
                object ret = mi.Invoke(recordObject, null);
                return ret;
            }
            else
            {
                throw new UnexpectedLogicWayException();
            }
        }

        List&lt;ListSourceGroupInfo&gt; IListServer.GetGroupInfo(DevExpress.Data.ListSourceGroupInfo groupInfo)
        {
            GroupingEventArgs gea = new GroupingEventArgs();
            gea.ParentGroupInfo = groupInfo;
            if (Request_GroupInfo != null)
            {
                Request_GroupInfo(this, gea);
                return gea.GroupInfo;
            }
            else
            {
                throw new NotImplementedException();
            }
        }
                
        #endregion

        #region Disabled
        
        #region IList Disabled

        int IList.Add(object value)
        {
            throw new NotImplementedException();
        }

        void IList.Clear()
        {
            throw new NotImplementedException();
        }

        bool IList.Contains(object value)
        {
            throw new NotImplementedException();
        }

        int IList.IndexOf(object value)
        {
            throw new NotImplementedException();
        }

        void IList.Insert(int index, object value)
        {
            throw new NotImplementedException();
        }

        bool IList.IsFixedSize
        {
            get { throw new NotImplementedException(); }
        }

        bool IList.IsReadOnly
        {
            get { throw new NotImplementedException(); }
        }

        void IList.Remove(object value)
        {
            throw new NotImplementedException();
        }

        void IList.RemoveAt(int index)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region ICollection Disabled

        void ICollection.CopyTo(Array array, int index)
        {
            throw new NotImplementedException();
        }

        bool ICollection.IsSynchronized
        {
            get { throw new NotImplementedException(); }
        }

        object ICollection.SyncRoot
        {
            get { throw new NotImplementedException(); }
        }

        #endregion

        #region IEnumerable Disabled

        IEnumerator IEnumerable.GetEnumerator()
        {
            throw new NotImplementedException();
        }

        #endregion

        #region ITypedList Disabled

        string ITypedList.GetListName(PropertyDescriptor[] listAccessors)
        {
            return "";
        }

        #endregion
        
        #region DevExpress.Data.IListServer Disabled

        /// &lt;summary&gt;
        /// disabled
        /// &lt;/summary&gt;
        event EventHandler&lt;ServerModeExceptionThrownEventArgs&gt; IListServer.ExceptionThrown
        {
            add { throw new NotImplementedException(); }
            remove { throw new NotImplementedException(); }
        }

        /// &lt;summary&gt;
        /// disabled
        /// &lt;/summary&gt;
        event EventHandler&lt;ServerModeInconsistencyDetectedEventArgs&gt; IListServer.InconsistencyDetected
        {
            add { throw new NotImplementedException(); }
            remove { throw new NotImplementedException(); }
        }

        /// &lt;summary&gt;
        /// disabled
        /// &lt;/summary&gt;
        IList IListServer.GetAllFilteredAndSortedRows()
        {
            throw new NotImplementedException();
        }

        /// &lt;summary&gt;
        /// disabled
        /// &lt;/summary&gt;
        int IListServer.GetRowIndexByKey(object key)
        {
            throw new NotImplementedException();
        }

        /// &lt;summary&gt;
        /// disabled
        /// &lt;/summary&gt;
        int IListServer.FindIncremental
            (
                DevExpress.Data.Filtering.CriteriaOperator expression,
                string value,
                int startIndex,
                bool searchUp,
                bool ignoreStartRow,
                bool allowLoop
            )
        {
            throw new NotImplementedException();
        }

        /// &lt;summary&gt;
        /// disabled
        /// &lt;/summary&gt;
        Dictionary&lt;object, object&gt; IListServer.GetTotalSummary()
        {
            throw new NotImplementedException();
        }

        /// &lt;summary&gt;
        /// disabled
        /// &lt;/summary&gt;
        object[] IListServer.GetUniqueColumnValues(DevExpress.Data.Filtering.CriteriaOperator expression, int maxCount,
        bool includeFilteredOut)
        {
            throw new NotImplementedException();
        }

        /// &lt;summary&gt;
        /// disabled
        /// &lt;/summary&gt;
        int IListServer.LocateByValue(DevExpress.Data.Filtering.CriteriaOperator expression, object value, int
            startIndex, bool searchUp)
        {
            throw new NotImplementedException();
        }

        /// &lt;summary&gt;
        /// disabled
        /// &lt;/summary&gt;
        void IListServer.Refresh()
        {
            throw new NotImplementedException();
        }

        #endregion

        #endregion
    }
}

AnswerRe: ObjectDataSource for DevExpress ASPxGtridView with enabled paging, sorting, grouping, external filters Pin
Mehul Harry28-Apr-11 14:03
Mehul Harry28-Apr-11 14:03 
Questioninput validation Pin
jashimu27-Apr-11 9:38
jashimu27-Apr-11 9:38 
AnswerRe: input validation Pin
gavindon27-Apr-11 9:49
gavindon27-Apr-11 9:49 
GeneralRe: input validation Pin
jashimu27-Apr-11 10:22
jashimu27-Apr-11 10:22 
GeneralRe: input validation Pin
gavindon27-Apr-11 10:38
gavindon27-Apr-11 10:38 
GeneralRe: input validation Pin
jashimu27-Apr-11 10:51
jashimu27-Apr-11 10:51 
GeneralRe: input validation Pin
Prasanta_Prince28-Apr-11 3:06
Prasanta_Prince28-Apr-11 3:06 
GeneralRe: input validation Pin
jashimu28-Apr-11 10:32
jashimu28-Apr-11 10:32 
AnswerRe: input validation Pin
m@dhu27-Apr-11 18:59
m@dhu27-Apr-11 18:59 
QuestionDeclarative vs Programmatic: opinions Pin
Brad Tumer27-Apr-11 8:55
Brad Tumer27-Apr-11 8:55 
AnswerRe: Declarative vs Programmatic: opinions Pin
Not Active28-Apr-11 2:39
mentorNot Active28-Apr-11 2:39 
GeneralRe: Declarative vs Programmatic: opinions Pin
Prasanta_Prince28-Apr-11 3:09
Prasanta_Prince28-Apr-11 3:09 
AnswerRe: Declarative vs Programmatic: opinions Pin
Renat Khabibulin4-May-11 17:09
Renat Khabibulin4-May-11 17:09 
Questionpdfbox error Pin
gavindon27-Apr-11 8:24
gavindon27-Apr-11 8:24 
QuestionSqlDataSource used in gridpage as well as to databind Pin
vanikanc27-Apr-11 6:00
vanikanc27-Apr-11 6:00 
AnswerRe: SqlDataSource used in gridpage as well as to databind Pin
vanikanc27-Apr-11 6:44
vanikanc27-Apr-11 6:44 
QuestionClearing Texbox text in ASP.Net MVC Pin
Priya Prk27-Apr-11 1:38
Priya Prk27-Apr-11 1:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.