コード例 #1
0
ファイル: ViewBoard.aspx.cs プロジェクト: comsiro/SimpleBoard
        public void displayTable()
        {
            string sBoardName = Request["BoardName"];
            string sBoardOrder = Request["OrderBy"];
            iPageSectorPosition = Convert.ToInt16(Request["PageSectorPosition"]);             
            iPageNum = Convert.ToInt16(Request["PageNum"]);
            bool bFlag = Convert.ToBoolean(Request["Flag"]);

            DBSQL db = new DBSQL();
            System.Data.DataTable dt = new System.Data.DataTable();
            dt = db.TSelect(sBoardName, sBoardOrder, bFlag);
            sBoardOrder = null;

            if (bFlag)
                bFlag = false;
            else
                bFlag = true;

            HtmlGenericControl tr = new HtmlGenericControl("tr");
            thead.Controls.Add(tr);

            try
            {
                foreach (DataColumn col in dt.Columns)
                {
                    HtmlGenericControl th = new HtmlGenericControl("th");
                    thead.Controls.Add(th);
                    HtmlGenericControl anchor = new HtmlGenericControl("a");
                    anchor.Attributes.Add("href", "ViewBoard.aspx?BoardName=" + sBoardName + "&OrderBy=" + col.ColumnName.ToString() + "&Flag=" + bFlag);
                    anchor.InnerText = col.ColumnName.ToString();
                    th.Controls.Add(anchor);
                }

                for(int i=dt.Rows.Count-(iMaxRowLengh*(iPageNum+1));i<dt.Rows.Count-(iMaxRowLengh * iPageNum);i++)
                {
                    if (i < 0)
                        i = 0;

                    HtmlGenericControl tr1 = new HtmlGenericControl("tr");
                    tbody.Controls.Add(tr1);
                    foreach (DataColumn col in dt.Columns)
                    {
                        HtmlGenericControl td = new HtmlGenericControl("td");
                        td.InnerText = dt.Rows[i][col].ToString();
                        tr1.Controls.Add(td);
                    }
                }

                HtmlGenericControl tr2 = new HtmlGenericControl("tr");
                tbody.Controls.Add(tr2);
                HtmlGenericControl td1 = new HtmlGenericControl("td");
                td1.Attributes.Add("colspan", dt.Columns.Count.ToString());
                td1.Attributes.Add("style", "text-align:center");
                tr2.Controls.Add(td1);

                int iTotalNumberofPage;
                if ((dt.Rows.Count % iMaxRowLengh) == 0)
                    iTotalNumberofPage = dt.Rows.Count / iMaxRowLengh;
                else
                    iTotalNumberofPage = dt.Rows.Count / iMaxRowLengh + 1;
                int iStartPage = iPageSectorLengh * iPageSectorPosition;
                int iLastPage = iPageSectorLengh * (iPageSectorPosition + 1);


                if (iPageSectorPosition > 0)
                {
                    HtmlGenericControl anchorHead = new HtmlGenericControl("a");
                    anchorHead.Attributes.Add("href", "ViewBoard.aspx?BoardName=" + sBoardName + "&PageNum=" + (iStartPage - iPageSectorLengh) + "&PageSectorPosition=" + (iPageSectorPosition -1));
                    anchorHead.InnerText = "<< ";
                    td1.Controls.Add(anchorHead);
                }


                for (iPageNum = iStartPage; iPageNum < iLastPage; iPageNum++)
                {
                    if ((iTotalNumberofPage - iPageNum) == 0)
                        break;

                    HtmlGenericControl anchorBody = new HtmlGenericControl("a");
                    anchorBody.Attributes.Add("href", "ViewBoard.aspx?BoardName=" + sBoardName + "&PageNum=" + iPageNum + "&PageSectorPosition=" + iPageSectorPosition);
                    anchorBody.InnerText = (iPageNum + 1) + " ";
                    td1.Controls.Add(anchorBody);
                }

                if ((iTotalNumberofPage - iLastPage) > 0)
                {
                    HtmlGenericControl anchorTail = new HtmlGenericControl("a");
                    anchorTail.Attributes.Add("href", "ViewBoard.aspx?BoardName=" + sBoardName + "&PageNum=" + (iLastPage+1) + "&PageSectorPosition=" + (iPageSectorPosition + 1));
                    anchorTail.InnerText = ">> ";
                    td1.Controls.Add(anchorTail);
                }
            }
            catch (Exception ex)
            {
                Log l = new Log();
                l.ErrorLog("Board Error:" + ex);
            }
            finally
            {

            }
        }