Results 1 to 3 of 3

Thread: How to create a control in Behind-Code?

  1. #1

    Thread Starter
    Addicted Member NinaWilliam's Avatar
    Join Date
    May 2005
    Location
    @Home
    Posts
    133

    How to create a control in Behind-Code?

    Hi,

    I am trying to write a code that creates a CheckBox inside htmlTable when the user selectes an option from a DropDownList..

    So, How can i do that?? Please help me..!!

    ASP.NET/VB.NET

  2. #2
    Member Nikhil Aggarwal's Avatar
    Join Date
    Jun 2005
    Location
    New Delhi, India
    Posts
    36

    Re: How to create a control in Behind-Code?

    You need to do the following

    1) Set the AutoPostBack property of the dropdownlist to TRUE.

    2) Get a refference to the HTML table in your codebehind.
    This can be done by doing 2 things
    a) add the runat="server" attribute to the decalration of the HTML Table in the aspx page
    b) Decalre a HTMLTable object for the class with the same id as the HTML Table
    VB Code:
    1. Protected Table1 As System.Web.UI.HtmlControls.HtmlTable
    3) Place the code for adding a checkbox in the SelectedIndexChanged event.
    Sample Code:
    VB Code:
    1. Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
    2.         Dim tr As New HtmlTableRow
    3.         Dim td As New HtmlTableCell
    4.         Dim chk As New CheckBox
    5.         td.Controls.Add(chk)
    6.         tr.Cells.Add(td)
    7.         Table1.Rows.Add(tr)
    8.     End Sub
    Nikhil Aggarwal

  3. #3

    Thread Starter
    Addicted Member NinaWilliam's Avatar
    Join Date
    May 2005
    Location
    @Home
    Posts
    133

    Re: How to create a control in Behind-Code?

    Thanks alot
    i will try it

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width