我正在使用gridview,并使用C#将一些行动态添加到gridview。但是在后面的代码中,当我执行grd.Rows.Count
时,它仅显示正常行的计数。
以下是我添加行的代码:
GridViewRow row = new GridViewRow(e.Row.RowIndex + descriptionRowIndex, e.Row.RowIndex + descriptionRowIndex, DataControlRowType.DataRow, DataControlRowState.Insert);
row_index = grdFileUpload1.Rows.Count + descriptionRowIndex;
// Adding Group Expand Collapse Cell
TableCell cell = new TableCell();
// Adding Header Cell
cell = new TableCell();
cell.HorizontalAlign = HorizontalAlign.Left;
cell.Text = "File Description";
cell.Font.Bold = true;
cell.ColumnSpan = 1;
cell.CssClass = "";
row.Cells.Add(cell);
// Adding Description Column
cell = new TableCell();
Label lblfile_desc = new Label();
cell.Controls.Add(lblfile_desc);//file_description.Value;
cell.Text = Session["file_description"].ToString();
cell.HorizontalAlign = HorizontalAlign.Right;
cell.ColumnSpan = 3;
cell.CssClass = "";
row.Cells.Add(cell);
row.ID = "collapsedRow" + row_index;
row.Attributes.Add("Style", "Display:none");
grdFileUpload1.Controls[0].Controls.AddAt(row_index, row);
感谢您的帮助。
答案 0 :(得分:0)
希望这会有所帮助。
DataTable dt = new DataTable();
dt.Columns.Add("COLUMN1", typeof(string));
DataRow NewRow = dt.NewRow();
NewRow[0] = "TEXT";
dt.Rows.Add(NewRow);
GridView1.DataSource = dt;
GridViewl.DataBind();