How to not overwrite table cell text when adding a

2019-08-21 14:29发布

I would like to add a link button control to a table cell, server side. The cell also has text in it, which gets overwritten by the control when I add it. How do I add the control to the cell and have the text remain as well?

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

2条回答
混吃等死
2楼-- · 2019-08-21 14:52

Add your text into 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);
查看更多
Melony?
3楼-- · 2019-08-21 15:02

I would simply add a Label before your LinkButton:

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);
查看更多
登录 后发表回答