Pages

Wednesday, October 5, 2011

Create Dynamic controls

Somtime we need controls created at runtime . here i am giving the example of TextBox. How to create multiple textboxes at runtime in Asp.Net. with the help of this you can also create other conrtols also.
Example:
--------
// 1.Create a div or Table where you have to create textboxes
// <table>
// <tr>
// <td id="DynamicTextBox" runat="server" style="width: 165px" align="left"></td>
// </tr>
// </table>

// 2. Create a list or collection

//Create Dynamic Textbox

int counterTextBox =0;

foreach (var item in collection)
{
      //Create Dynamic Textbox
      System.Web.UI.WebControls.TextBox tb = new System.Web.UI.WebControls.TextBox();
      tb.Width = 495;
      tb.Height = 18;
      tb.TextMode = TextBoxMode.SingleLine;
      tb.ID = "TextBox_ID" + ++coutnerTextbox;
      DynamicTextBox.Controls.Add(tb);
      DynamicTextBox.Controls.Add(new LiteralControl("<br/>"));          

} 

2 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Useful post. I got more information from this blog. Thank you so much for sharing this amazing Post.Vendor Helpdesk
    top ca firms in chennai
    Customer Helpdesk

    ReplyDelete