コード例 #1
0
ファイル: index.aspx.cs プロジェクト: miragefox/Phoenix
        protected void GetData()
        {
            RequestModel requestModel = new RequestModel();
            var          requestList  = requestModel.GetAllRequest();

            RequestGridView.DataSource = requestList;
            RequestGridView.DataBind();
            int pageSize = RequestGridView.AllowPaging == true ? RequestGridView.PageSize : 10;//默认行数是10行

            if (RequestGridView.Rows.Count == 0)
            {
                DataTable dt = new DataTable();
                // 当DataSource为空时绑定之,否则Gridview控件就不能显示
                DataRow dr;
                for (int i = 0; i < RequestGridView.Columns.Count - 1; i++)
                {
                    dt.Columns.Add(new DataColumn(((BoundField)RequestGridView.Columns[i]).DataField, typeof(string)));
                    dr    = dt.NewRow();
                    dr[i] = "&nbsp;";
                }
                dt.Columns.Add("Action");
                dr    = dt.NewRow();
                dr[6] = "&nbsp;";
                for (int j = 0; j < pageSize - RequestGridView.Rows.Count; j++)
                {
                    dr = dt.NewRow();
                    dt.Rows.Add(dr);
                }
                RequestGridView.DataSource = dt;
                RequestGridView.DataBind();
            }
            else
            {
                for (int i = 0; i < 10 - RequestGridView.Rows.Count; i++)
                {
                    int         rowIndex = RequestGridView.Rows.Count + i + 1;
                    GridViewRow row      = new GridViewRow(rowIndex, -1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal);
                    for (int j = 0; j < RequestGridView.Columns.Count - 3; j++)
                    {
                        TableCell cell = new TableCell();
                        cell.Text = "&nbsp;";
                        row.Controls.Add(cell);
                        row.Attributes.Add("BorderColor ", "#d2d2d2");
                    }

                    RequestGridView.Controls[0].Controls.AddAt(rowIndex, row);
                }
            }
        }