Dynamically add controls in Table Footer Row using C# and VB.Net in ASP.Net

Last Reply 20 days ago By pandeyism

Posted 20 days ago

how to add dynamic textbox in table footer row.

i want to add image and textbox in footer row with fixed position

my code:- 

Table tdata = new Table();
TableRow tr = new TableRow();
TableCell tc1 = new TableCell();               

Image commentimage1 = new Image();
commentimage1.ID = "commentimage_ ";
// commentimage.ImageUrl = "data:Image/png;base64," + strBase66;
commentimage1.Attributes.Add("class", "img-thumbnail");
commentimage1.Style.Add("width", "55px");
commentimage1.Style.Add("height", "55px");

TextBox txt = new TextBox();
txt.ID = "txt";

tc1.Controls.Add(commentimage1);
tc1.Controls.Add(txt);

tr.Controls.Add(tc1);
Panel1.Controls.Add(tr);

 

Posted 20 days ago

Hi IamAzhar,

Refer below code.

Code

C#

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        Table tdata = new Table();
        TableRow tr = new TableRow();
        TableCell tc1 = new TableCell();
        Image commentimage1 = new Image();
        commentimage1.ID = "commentimage_ ";
        commentimage1.ImageUrl = "Chrysanthemum.jpg";
        commentimage1.Attributes.Add("class", "img-thumbnail");
        tdata.Style.Add("width", "200px");
        tdata.Style.Add("height", "150px");
        commentimage1.Style.Add("width", "50px");
        commentimage1.Style.Add("height", "50px");
        tdata.Style.Add("border", "1px solid #ccc");
        tc1.Style.Add("padding-top", "100px");
        tc1.Style.Add("padding-left", "50px");
        TextBox txt = new TextBox();
        txt.ID = "txt";           
        tc1.Controls.Add(commentimage1);
        tc1.Controls.Add(txt);
        tr.Controls.Add(tc1);
        tr.Controls.Add(tc1);
        tdata.Controls.Add(tr);
        form1.Controls.Add(tdata);
    }
}

VB.Net

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    If Not Me.IsPostBack Then
        Dim tdata As Table = New Table()
        Dim tr As TableRow = New TableRow()
        Dim tc1 As TableCell = New TableCell()
        Dim commentimage1 As Image = New Image()
        commentimage1.ID = "commentimage_ "
        commentimage1.ImageUrl = "Chrysanthemum.jpg"
        commentimage1.Attributes.Add("class", "img-thumbnail")
        tdata.Style.Add("width", "200px")
        tdata.Style.Add("height", "150px")
        commentimage1.Style.Add("width", "50px")
        commentimage1.Style.Add("height", "50px")
        tdata.Style.Add("border", "1px solid #ccc")
        tc1.Style.Add("padding-top", "100px")
        tc1.Style.Add("padding-left", "50px")
        Dim txt As TextBox = New TextBox()
        txt.ID = "txt"
        tc1.Controls.Add(commentimage1)
        tc1.Controls.Add(txt)
        tr.Controls.Add(tc1)
        tr.Controls.Add(tc1)
        tdata.Controls.Add(tr)
        form1.Controls.Add(tdata)
    End If
End Sub

Screenshot