【问题标题】:Dynamically added row didn't show in GridView.Rows.CountGridView.Rows.Count 中未显示动态添加的行
【发布时间】:2020-04-05 04:57:15
【问题描述】:

我正在研究一个网格视图,并使用 C# 向网格视图动态添加一些行。但是在我执行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);

感谢您的帮助。

【问题讨论】:

    标签: asp.net gridview webforms


    【解决方案1】:

    希望这会有所帮助。

    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();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-24
      • 1970-01-01
      • 2020-12-31
      相关资源
      最近更新 更多