IT Community - Software Programming, Web Development and Technical Support

Create dropdownlist at runtime

This is a discussion on Create dropdownlist at runtime within the ASP and ASP.NET Programming forums, part of the Web Development category; Hi , I want to create the dropdownlist dynamically based on the selected value of dropdown. <aspropDownList ID="cascadeDropDown&...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > ASP and ASP.NET Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 12-20-2007, 02:55 AM
shaalini shaalini is offline
D-Web Analyst
 
Join Date: Apr 2007
Posts: 342
shaalini is on a distinguished road
Default Create dropdownlist at runtime

Hi ,
I want to create the dropdownlist dynamically based on the selected value of dropdown.

<aspropDownList ID="cascadeDropDown" runat="server" AppendDataBoundItems="true" AutoPostBack="true" >
<asp:ListItem Value="0" Text="Test">
</asp:ListItem>
<asp:ListItem Value="1" Text="seasoning">
</asp:ListItem>
<asp:ListItem Value="2" Text="test">
</asp:ListItem>
<asp:ListItem Value="3" Text="Food">
</asp:ListItem>
</aspropDownList>
<asp:PlaceHolder id="PlaceHolder1" runat="server"></asp:PlaceHolder>

i m creating the dropdown based on the selected value of cascadedropdown
int count = System.Convert.ToInt32(cascadeDropDown.SelectedVal ue);
for (int i = 0; i < count; i++)
{

DropDownList DDL = new DropDownList();


DDL.ID = "DDL" + i.ToString();
DDL.Items.Add(new ListItem("Veg", "0"));
DDL.Items.Add(new ListItem("Type", "1"));
DDL.Items.Add(new ListItem("Stored", "2"));
DDL.AutoPostBack = true;
DDL.SelectedIndexChanged += new System.EventHandler(this.dropListEventHandler);
PlaceHolder1.Controls.Add(DDL);

}
and it creates as DDL0,DDL1,DDL2....
void dropListEventHandler(object sender, EventArgs e)
{
DropDownList dropDownListRuntTime = (DropDownList)sender;
string clientId = dropDownListRuntTime.ClientID;
// "dropDownListRuntTime.SelectedValue" gives you the selected value
int count = System.Convert.ToInt32(dropDownListRuntTime.Select edValue);
for (int i = 0; i < count; i++)
{
DropDownList DDLparent = new DropDownList();
DDLparent.ID = "DDLparent" + i.ToString();
DDLparent.Items.Add(new ListItem("sFood", "0"));
DDLparent.Items.Add(new ListItem("sWine", "1"));
DDLparent.Items.Add(new ListItem("sTest", "2"));
DDLparent.AutoPostBack = true;
GetDropdownIndex(DDLparent);
PlaceHolder1.Controls.Add(DDLparent);

}
If i select DDL0, based on selected value it creates as DDLparent0.......... i should get the dropdown based on the DDLParent0.... and loop should continue....When I select DDLParent0.onselectindexchangedevent is not fired
__________________
Shaalini.S
Be the Best of Whatever you are...

Last edited by shaalini : 12-20-2007 at 03:12 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 02-14-2008, 08:16 PM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo to kingmaker
Default Re: Create dropdownlist at runtime

You have to add DDLparent.onselectedindex chage property and assign method to it
__________________
The KINGMAKER
Makes Every Thing Possible

Stuffs (My Blog)
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java without runtime? STARGAZER Java Programming 1 12-28-2007 11:29 PM
System.Runtime.InteropServices.COMException in windows vista $enthil C# Programming 3 11-14-2007 09:51 PM
how to rectify java script runtime error vel.m8 HTML, CSS and Javascript Coding Techniques 1 11-04-2007 09:42 PM
Microsoft JScript runtime error: 'offsetTop' is null or not an object vel.m8 HTML, CSS and Javascript Coding Techniques 0 11-01-2007 10:52 PM
DropdownList in Editable Datagrid shaalini ASP and ASP.NET Programming 3 10-26-2007 06:07 AM


All times are GMT -7. The time now is 07:13 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0