【问题标题】:How to not overwrite table cell text when adding a control添加控件时如何不覆盖表格单元格文本
【发布时间】:2012-07-27 18:21:53
【问题描述】:

我想在服务器端的表格单元格中添加一个链接按钮控件。该单元格中还有文本,当我添加它时,它会被控件覆盖。如何将控件添加到单元格并保留文本?

        //Create a table cell and add text to it
        TableCell commentCell = new TableCell();
        commentCell.Text = "Text to remain in the cell."

        //Create a linkbtn and add it to the table cell
        LinkButton lbtnComments = new LinkButton();
        lbtnComments.Text = "...";
        lbtnComments.Style["float"] = "right";
        commentCell.Controls.Add(lbtnComments);

【问题讨论】:

    标签: asp.net controls


    【解决方案1】:

    我只需在您的LinkButton 之前添加一个Label

    TableCell commentCell = new TableCell();
    Label lblComment = new Label();
    lblComment.Text = "Text to remain in the cell."
    commentCell.Controls.Add(lblComment);
    LinkButton lbtnComments = new LinkButton();
    commentCell.Controls.Add(lbtnComments);
    

    【讨论】:

      【解决方案2】:

      将您的文本添加到 LiteralControl 中:

          //Create a table cell and add text to it
          TableCell commentCell = new TableCell();
          commentCell.Controls.Add(new LiteralControl("Text to remain in the cell.");
      
          //Create a linkbtn and add it to the table cell
          LinkButton lbtnComments = new LinkButton();
          lbtnComments.Text = "...";
          lbtnComments.Style["float"] = "right";
          commentCell.Controls.Add(lbtnComments);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-03-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多