本文介绍了[已解决]扩展GridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试扩展GridView以与DataPager一起使用. IPageableItemContainer的所有方法均已实现,但是我得到了:

dnetbs.Controls.DataGridExtended'' is not allowed here because it does not extend class ''System.Web.UI.UserControl


Hi,

I''m trying to extend a GridView to work with a DataPager. All the methods of IPageableItemContainer have been implemented, however I''m getting:

dnetbs.Controls.DataGridExtended'' is not allowed here because it does not extend class ''System.Web.UI.UserControl


namespace dnetbs.Controls
{
    public partial class DataGridExtended : GridView, IPageableItemContainer
    {
        public void SetDataSource(object DataSrc)
        {
            this.GridView1.DataSource = DataSrc;
        }
        public DataGridExtended()
            : base()
        {
            PagerSettings.Visible = false;
        }

        public event EventHandler<PageEventArgs> TotalRowCountAvailable;
        public int MaximumRows
        {
            get { return this.PageSize; }
        }
        public int StartRowIndex
        {
            get { return (this.PageSize * this.PageIndex); }
        }
        public virtual void OnTotalRowCountAvailable(PageEventArgs e)
        {
            if (TotalRowCountAvailable != null)
                TotalRowCountAvailable(this, e);
        }
        public virtual void SetPageProperties(int startRowIndex, int maximumRows, bool dataBind)
        {
            if (dataBind)
            {
                PageSize = maximumRows;
                int newPageIndex = (startRowIndex / PageSize);
                if (PageIndex != newPageIndex)
                {
                    OnPageIndexChanging(new GridViewPageEventArgs(newPageIndex));
                    PageIndex = newPageIndex;
                    OnPageIndexChanged(EventArgs.Empty);
                }
            }
            RequiresDataBinding = dataBind;
        }
        //Gets row count from SqlDataSource and the like... 
        private int _GetTotalRowsFromDataSourceObject(IEnumerable dataSource)
        {
            DataSourceView view = this.GetData();
            if (AllowPaging && view.CanPage && view.CanRetrieveTotalRowCount)
                return base.SelectArguments.TotalRowCount;
            else
                return (PageIndex * PageSize) + _GetSourceCount(dataSource);
        }
        //Gets the row count from a manually bound source or from a source in viewstate 
        private int _GetSourceCount(IEnumerable dataSource)
        {
            ICollection source = dataSource as ICollection;
            //condition ? first_expression : second_expression; returns one of two values depending on the value of a Boolean expression
            return source != null ? source.Count : (from x in dataSource.OfType<object>() select 1).Sum();
        }
        protected override int CreateChildControls(IEnumerable dataSource, bool dataBinding)
        {
            int baseResult = base.CreateChildControls(dataSource, dataBinding);
            if (dataSource != null)
            {
                int dataSourceCount = (IsBoundUsingDataSourceID && dataBinding) ?
                    _GetTotalRowsFromDataSourceObject(dataSource) :
                    _GetSourceCount(dataSource);
                OnTotalRowCountAvailable(new PageEventArgs(StartRowIndex, MaximumRows, dataSourceCount));
            }
            return baseResult;
        }
    }
}



更新:
由OP自己解决.



UPDATE:
Resolved by OP himself.

推荐答案


这篇关于[已解决]扩展GridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 03:15