Exemplo n.º 1
0
        /// <summary>
        /// Cria uma linha na grid informada.
        /// </summary>
        /// <param name="gridView"></param>
        /// <param name="rowIndex"></param>
        /// <param name="dataSourceIndex"></param>
        /// <param name="rowType"></param>
        /// <param name="rowState"></param>
        /// <param name="dataBind"></param>
        /// <param name="dataItem"></param>
        /// <param name="fields"></param>
        /// <param name="rows"></param>
        /// <param name="pagedDataSource"></param>
        /// <returns></returns>
        public static System.Web.UI.WebControls.GridViewRow CreateRow(
            this System.Web.UI.WebControls.GridView gridView,
            int rowIndex, int dataSourceIndex, System.Web.UI.WebControls.DataControlRowType rowType,
            System.Web.UI.WebControls.DataControlRowState rowState, bool dataBind, object dataItem,
            System.Web.UI.WebControls.DataControlField[] fields, System.Web.UI.WebControls.TableRowCollection rows,
            System.Web.UI.WebControls.PagedDataSource pagedDataSource)
        {
            var createRowMethod2 = typeof(System.Web.UI.WebControls.GridView).GetMethod("CreateRow",
                                                                                        System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance,
                                                                                        null, new Type[]
            {
                typeof(int),                                           // rowIndex
                typeof(int),                                           // dataSourceIndex
                typeof(System.Web.UI.WebControls.DataControlRowType),  // rowType
                typeof(System.Web.UI.WebControls.DataControlRowState), // rowState
                typeof(bool),                                          // dataBind
                typeof(object),                                        // dataItem,
                typeof(System.Web.UI.WebControls.DataControlField[]),  // fields
                typeof(System.Web.UI.WebControls.TableRowCollection),  // rows
                typeof(System.Web.UI.WebControls.PagedDataSource)      // pagedDataSource
            }, null);

            try
            {
                return((System.Web.UI.WebControls.GridViewRow)createRowMethod2.Invoke(gridView, new object[]
                {
                    rowIndex, dataSourceIndex, rowType, rowState, dataBind, dataItem, fields, rows, pagedDataSource
                }));
            }
            catch (System.Reflection.TargetInvocationException ex)
            {
                throw ex.InnerException;
            }
        }
        /// <summary>
        /// 用PagedDataSource实现分页
        /// </summary>
        /// <param name="_Page"></param>
        /// <param name="_DS"></param>
        /// <param name="_Repeater"></param>
        private void DoPage(System.Web.UI.Page _Page, System.Data.DataSet _DS, System.Web.UI.WebControls.Repeater _Repeater)
        {
            int S_index = int.Parse(M_HiddenField.Value.ToString());

            System.Web.UI.WebControls.PagedDataSource _PDS = new System.Web.UI.WebControls.PagedDataSource();
            _PDS.DataSource  = _DS.Tables[0].DefaultView;
            _PDS.AllowPaging = true;

            _PDS.PageSize = _PageSize;
            _PageCount    = _PDS.PageCount;

            if (S_index <= 0)
            {
                _PageIndex = 1;
            }
            else if (S_index >= _PageCount - 1)
            {
                _PageIndex = _PageCount;
            }
            else
            {
                _PageIndex = S_index + 1;
            }

            //清空
            __HtmlGenericControl.Controls.Clear();

            //创建四个按钮前两个
            CreateFirstButton();
            CreatePrevButton();

            //创建分页数据
            string sumNum = _DS.Tables[0].Rows.Count.ToString();

            CreateShuju(_PageIndex.ToString(), _PageCount.ToString(), sumNum);

            //创建四个按钮后两个
            CreateNextButton();
            CreateLastButton();

            _PDS.CurrentPageIndex = _PageIndex - 1;
            M_HiddenField.Value   = Convert.ToString(_PageIndex - 1);
            //((System.Web.UI.WebControls.HiddenField)_Page.FindControl(_SessionString)).Value = M_HiddenField.Value;
            ((System.Web.UI.WebControls.HiddenField)_Repeater.Parent.FindControl(_SessionString)).Value = M_HiddenField.Value;

            _Repeater.DataSource = _PDS;
            _Repeater.DataBind();
        }
Exemplo n.º 3
0
 /// <summary>
 /// 用PagedDataSource实现分页
 /// </summary>
 /// <param name="_DS">DataSet对象</param>
 /// <param name="S_index">当前页的索引</param>
 /// <returns>PagedDataSource对象</returns>
 public System.Web.UI.WebControls.PagedDataSource Paged(System.Data.DataSet _DS, int S_index)
 {
     System.Web.UI.WebControls.PagedDataSource _PDS = new System.Web.UI.WebControls.PagedDataSource();
     _PDS.DataSource  = _DS.Tables[0].DefaultView;
     _PDS.AllowPaging = true;
     _PDS.PageSize    = _PageSize;
     _PageCount       = _PDS.PageCount;
     if (S_index <= 0)
     {
         _PageIndex = 0;
     }
     else if (S_index >= _PageCount - 1)
     {
         _PageIndex = _PageCount - 1;
     }
     else
     {
         _PageIndex = S_index;
     }
     _PDS.CurrentPageIndex = _PageIndex;
     return(_PDS);
 }
Exemplo n.º 4
0
    protected override void InitializePager(System.Web.UI.WebControls.GridViewRow row, int columnSpan, System.Web.UI.WebControls.PagedDataSource pagedDataSource)
    {
        HtmlGenericControl ul = new HtmlGenericControl("ul");

        ul.Attributes.Add("class", "pagination pull-right");
        AddPager(ul, commandArgument: "First", text: "<span class='glyphicon glyphicon-fast-backward'></span>");
        for (int i = 0; i < PageCount; i++)
        {
            AddPager(ul, i);
        }
        AddPager(ul, commandArgument: "Last", text: "<span class='glyphicon glyphicon-fast-forward'></span>");
        row.CssClass = "table-footer";
        row.Cells.Add(new System.Web.UI.WebControls.TableCell());
        row.Cells[0].ColumnSpan = columnSpan;
        row.Cells[0].Controls.AddAt(0, ul);
    }