简体   繁体   中英

How to add Dynamic Field in Dynamic Page in ASP.NET in C#

I want to add one Dynamic Field as "ADD MORE SKILLS" which shows some Textbox and Label will come on clicking this link. You can see this kind of example on some Shine.com, TimesJob etc.....

Here is Something to start with. Modify According to your need. Create a new button and onclick of button create the new controls dynamically. I have created a label and textbox dynamically in the below mentioned code ASP Button

<asp:Button ID="AddMoreSkills" runat="server" Text="Add More Skills" 
            onclick="AddMoreSkills_Click" />

OnClick event in C#

protected void AddMoreSkills_Click(object sender, EventArgs e)
{
    Table tblmain = new Table();
    tblmain.ID = "tblmain";
    tblmain.Width = Unit.Percentage(100);
    tblmain.Attributes.CssStyle.Add("margin-top", "5px");
    tblmain.Attributes.CssStyle.Add("margin-bottom", "5px");

    TableCell tblTCell;
    TableRow tblRow = new TableRow();
    TableCell tblCell = new TableCell();

    tblRow = new TableRow();

    //Create Label Dynamically
    tblCell = new TableCell();
    Label lblTown = new Label();
    lblTown.ID = "lblSkill";
    lblTown.Text = "Skill";

    //Add label to table cell
    tblCell.Controls.Add(lblTown);
    tblRow.Cells.Add(tblCell);

    //Create TextBox Dynamically
    TextBox txtSkill = new TextBox();
    txtSkill.ID = "txtSkill";

    //Add TextBox to table cell
    tblTCell = new TableCell();
    tblTCell.Controls.Add(txtSkill);
    tblRow.Cells.Add(tblTCell);
    tblmain.Rows.Add(tblRow);

    form1.Controls.Add(tblmain);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM