【问题标题】:Insert Div in gridview cell在gridview单元格中插入div
【发布时间】:2013-01-29 10:07:37
【问题描述】:

我有一个gridview,在RowDatabound 事件中我试图在单元格内插入一个div 并设置innerhtml。在调试时,div 的 innerHTML 充满了文本。但是当它运行时 ii 是一个空单元格。有什么帮助吗?

        protected void grdThreat_RowDataBound(object sender, GridViewRowEventArgs e)
    {

        if (e.Row.RowType == DataControlRowType.DataRow)
        {

            HtmlGenericControl div = new HtmlGenericControl("div");

            div.InnerHtml = e.Row.Cells[4].Text;
            e.Row.Cells[4].Controls.Add(div);
   }
}

【问题讨论】:

    标签: c# asp.net gridview


    【解决方案1】:

    面板将呈现为div,因此您可以使用它:

    Panel mainPanel = new Panel();
    
    mainPanel .Controls.Add(new LiteralControl(e.Row.Cells[4].Text));
    
    e.Row.Cells[4].Controls.Add(mainPanel);
    

    【讨论】:

    • 嗯,它可以工作,但我的 e.row.cells[4].Text 包含像
      等 Html 标签。我可以在单元格中看到
      而不是换行。
    • 嗬,你想要其他方式然后尝试 mainPanel.Controls.Add(new Label(e.Row.Cells[4].Text));
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-28
    • 1970-01-01
    • 2018-03-10
    • 1970-01-01
    • 2013-11-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多