create a dropdownlist..http://forums.asp.net/t/1798572.aspx/1?create+a+dropdownlist+Tue, 01 May 2012 09:52:32 -040017985724958646http://forums.asp.net/p/1798572/4958646.aspx/1?create+a+dropdownlist+create a dropdownlist.. <p>I'm a novice in asp.net. I'm trying to create a modal calculator that has a dropdownlist. Dropdown list has number 1-14. if i choose any of the numbers i will be able to have same number of textbox for data entry. thank you</p> 2012-04-30T17:03:42-04:004958881http://forums.asp.net/p/1798572/4958881.aspx/1?Re+create+a+dropdownlist+Re: create a dropdownlist.. <p>This is not easy to do, I worked on a project like this for over a month to finally figure it out, but I got it working....</p> <p>You need to do this in the pageInit event because you need to repeat it on every post back to redisplay the controls. There is a pretty good tutorial on teh fourguysfromrolla web site.</p> <pre class="prettyprint">For I = 1 To 15 ' *************************************************** ' * Build English Header Dim lstD As New DropDownListBox lstD.ID = &quot;lstDEdit&quot; &amp; I.ToString(&quot;D2&quot;) ph.Controls.Add(lstD) ' ph = Placeholder in Gridview to locate the control Dim litCtrlD As New Literal litCtrlD.ID = &quot;litCtrlD&quot; &amp; I.ToString(&quot;D2&quot;) litCtrlD.Text = &quot;&lt;br /&gt;&quot; ph.Controls.Add(litCtrlD) ' *************************************************** ' * Build English DropDownListBox Dim lstA As New DropDownListBox lstA.ID = &quot;lstAEdit&quot; &amp; I.ToString(&quot;D2&quot;) ph.Controls.Add(lstA) Dim litCtrla As New Literal litCtrla.ID = &quot;litCtrla&quot; &amp; I.ToString(&quot;D2&quot;) litCtrla.Text = &quot;&lt;br /&gt;&quot; ph.Controls.Add(litCtrla) Next</pre> <p>Look up working with Literal controls..</p> <p>My project requried textbox not DDLs though.</p> <p>&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p> 2012-04-30T19:39:40-04:004959221http://forums.asp.net/p/1798572/4959221.aspx/1?Re+create+a+dropdownlist+Re: create a dropdownlist.. <p>I would recommend you to go through this post to understand about creating and accessing controls dynamically</p> <p><a href="http://aspnet.4guysfromrolla.com/articles/092904-1.aspx">http://aspnet.4guysfromrolla.com/articles/092904-1.aspx</a></p> <p><a href="http://www.aspnettutorials.com/tutorials/controls/control-dym-aspnet2-csharp.aspx">http://www.aspnettutorials.com/tutorials/controls/control-dym-aspnet2-csharp.aspx</a></p> <p><a href="http://ranafaisal.wordpress.com/2009/02/17/dynamically-adding-removing-textboxes-in-aspnet-repeater/">http://ranafaisal.wordpress.com/2009/02/17/dynamically-adding-removing-textboxes-in-aspnet-repeater/</a></p> 2012-05-01T05:09:04-04:004959598http://forums.asp.net/p/1798572/4959598.aspx/1?Re+create+a+dropdownlist+Re: create a dropdownlist.. <p>Hey</p> <p>First Create a Dropdown with 14 listitems and take a PLACEHOLDER where the textbox will be created.</p> <p>Code at Default.aspx page is:</p> <p>&lt;asp:DropDownList ID=&quot;DropDownList1&quot; runat=&quot;server&quot; AutoPostBack=&quot;True&quot; <br> onselectedindexchanged=&quot;DropDownList1_SelectedIndexChanged&quot;&gt;<br> &lt;asp:ListItem&gt;1&lt;/asp:ListItem&gt;<br> &lt;asp:ListItem&gt;2&lt;/asp:ListItem&gt;<br> &lt;asp:ListItem&gt;3&lt;/asp:ListItem&gt;<br> &lt;asp:ListItem&gt;4&lt;/asp:ListItem&gt;<br> &lt;asp:ListItem&gt;5&lt;/asp:ListItem&gt;<br> &lt;asp:ListItem&gt;6&lt;/asp:ListItem&gt;<br> &lt;asp:ListItem&gt;7&lt;/asp:ListItem&gt;<br> &lt;asp:ListItem&gt;8&lt;/asp:ListItem&gt;<br> &lt;asp:ListItem&gt;9&lt;/asp:ListItem&gt;<br> &lt;asp:ListItem&gt;10&lt;/asp:ListItem&gt;<br> &lt;asp:ListItem&gt;11&lt;/asp:ListItem&gt;<br> &lt;asp:ListItem&gt;12&lt;/asp:ListItem&gt;<br> &lt;asp:ListItem&gt;13&lt;/asp:ListItem&gt;<br> &lt;asp:ListItem&gt;14&lt;/asp:ListItem&gt;<br> &lt;/asp:DropDownList&gt;</p> <p>&lt;p&gt;<br> &lt;asp:PlaceHolder ID=&quot;PlaceHolder1&quot; runat=&quot;server&quot;&gt;<br> &lt;/asp:PlaceHolder&gt;<br> &lt;/p&gt;&lt;/div&gt;<br> &lt;/form&gt;</p> <p>Code at Default.aspx.cs file will be:</p> <p>protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)<br> {<br> PlaceHolder plc1 = new PlaceHolder();<br> for (int i = 1; i &lt;= Convert.ToInt16(DropDownList1.SelectedValue.ToString()); i&#43;&#43;)<br> {<br> TextBox text = new TextBox();<br> text.ID = &quot;textbox&quot; &#43; i;<br> plc1.Controls.Add(new LiteralControl(&quot;&lt;table width='100%'&gt;&lt;tr&gt;&lt;td width='50%'&gt;Full Name:&lt;/td&gt;&lt;td&gt;&quot;));<br> plc1.Controls.Add(text);<br> plc1.Controls.Add(new LiteralControl(&quot;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&quot;));<br> }<br> PlaceHolder1.Controls.Add(plc1);<br> }</p> <p>Hope this will help you.</p> 2012-05-01T09:52:32-04:00