예제 #1
0
        /// <summary>
        /// 绑定数据到DataGrid控件GoodsDataGrid上
        /// </summary>
        private void BindDataGrid()
        {
            //创建操作员记录数据表类实例
            Goods goods = new Goods();
            //获取记录数据
            DataTable dt = goods.BindNodes(this.txtId.Text.Trim());//goods.Bind();
            DataView  dv = new DataView();

            dt.TableName = "Goods";
            if (dt != null)
            {
                dv.Table = dt;
                dv.Sort  = " Price DESC";

                if (ViewState["Condition"] != null && ViewState["Condition"].ToString() != "")
                {
                    dv.RowFilter = ViewState["Condition"].ToString();
                }
                else
                {
                    dv = dt.DefaultView;
                }

                //新增ID自增值列绑定
                dt.Columns.Add(new DataColumn("idno", Type.GetType("System.Int32")));
                int intCountRecNum = dv.Count;  //获取数据表记录数
                for (int i = 0; i < intCountRecNum; i++)
                {
                    dv[i]["idno"] = i + 1;
                }
                GoodsDataGrid.DataSource = dv;
                int PageCount = 0;
                if (intCountRecNum % GoodsDataGrid.PageSize == 0)
                {
                    PageCount = intCountRecNum / GoodsDataGrid.PageSize;
                }
                else
                {
                    PageCount = intCountRecNum / GoodsDataGrid.PageSize + 1;
                }

                if (PageCount != 0 && GoodsDataGrid.CurrentPageIndex >= PageCount)
                {
                    GoodsDataGrid.CurrentPageIndex = PageCount - 1;
                }

                GoodsDataGrid.DataBind();
                lblRecNum.Text = intCountRecNum.ToString();     //显示总记录数
                ShowStats();                                    //显示页数信息
            }
        }
예제 #2
0
        protected void tvCategory_SelectedNodeChanged(object sender, EventArgs e)
        {
            string id = tvCategory.SelectedNode.Value;

            this.txtId.Text = id;
            //创建操作员记录数据表类实例
            Goods goods = new Goods();
            //获取记录数据
            DataTable dt = goods.BindNodes(id);
            DataView  dv = new DataView();

            dt.TableName = "Goods";
            if (dt != null)
            {
                dv.Table = dt;
                dv.Sort  = " Price DESC";

                //if (ViewState["Condition"] != null && ViewState["Condition"].ToString() != "")
                //    dv.RowFilter = ViewState["Condition"].ToString();
                //else
                dv = dt.DefaultView;

                //新增ID自增值列绑定
                dt.Columns.Add(new DataColumn("idno", Type.GetType("System.Int32")));
                int intCountRecNum = dv.Count;  //获取数据表记录数
                for (int i = 0; i < intCountRecNum; i++)
                {
                    dv[i]["idno"] = i + 1;
                }
                GoodsDataGrid.DataSource = dv;
                int PageCount = 0;
                if (intCountRecNum % GoodsDataGrid.PageSize == 0)
                {
                    PageCount = intCountRecNum / GoodsDataGrid.PageSize;
                }
                else
                {
                    PageCount = intCountRecNum / GoodsDataGrid.PageSize + 1;
                }

                if (PageCount != 0 && GoodsDataGrid.CurrentPageIndex >= PageCount)
                {
                    GoodsDataGrid.CurrentPageIndex = PageCount - 1;
                }

                GoodsDataGrid.DataBind();
                lblRecNum.Text = intCountRecNum.ToString();     //显示总记录数
                ShowStats();                                    //显示页数信息
            }
        }