| | |
how to create a dynamic dropdownlist?
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
hi all,
do anyone knows how to create a dynamic dropdownlist? the dropdownlist will retrieve the list items from database..
eg: below is code for static dropdownlist where i declare the listitem myself.. but how should i declare listitem retreive from database?
thanks..
do anyone knows how to create a dynamic dropdownlist? the dropdownlist will retrieve the list items from database..
eg: below is code for static dropdownlist where i declare the listitem myself.. but how should i declare listitem retreive from database?
ASP.NET Syntax (Toggle Plain Text)
<asp:dropdownlist id="ddl" Runat="server"> <asp:ListItem Value="1">A</asp:ListItem> <asp:ListItem Value="2">B</asp:ListItem> <asp:ListItem Value="3">C</asp:ListItem> </asp:dropdownlist>
thanks..
cheers,
ohgosh
ohgosh
•
•
Join Date: Jul 2005
Posts: 483
Reputation:
Solved Threads: 19
if you can get the information out of the database and into a DataTable all you need to do is:
if you need help getting it from the database into the datatable let me know
ASP.NET Syntax (Toggle Plain Text)
DropDownList1.DataSource=dataTableName; DropDownList1.DataTextField="NameofDatabaseColumn"; DropDownList1.DataValueField="NameofDatabaseColumn"; DropDownList1.DataBind();
if you need help getting it from the database into the datatable let me know
•
•
Join Date: Oct 2008
Posts: 2
Reputation:
Solved Threads: 0
See following to create dynamic dropdown list with event handler
http://urenjoy.blogspot.com/2009/03/...in-aspnet.html
http://urenjoy.blogspot.com/2009/03/...in-aspnet.html
hi,
check this code
check this code
ASP.NET Syntax (Toggle Plain Text)
<asp:DropDownList ID="ddlist" runat="server" ></asp:DropDownList> protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { binddropdown(); } } public void binddropdown() { SqlConnection conn = new SqlConnection("Data Source='localhost';Initial Catalog='Northwind';Integrated Security=SSPI;Persist Security Info=False "); SqlDataAdapter da = new SqlDataAdapter("", conn); da.SelectCommand = new SqlCommand("select CategoryName,CategoryID from Categories", conn); DataSet ds = new DataSet(); da.Fill(ds, "data"); ddlist.AppendDataBoundItems = true; ListItem li = new ListItem(); li.Text = "Select"; li.Value = "Select"; ddlist.Items.Add(li); ddlist.DataSource = ds.Tables[0].DefaultView; ddlist.DataTextField = "CategoryName"; ddlist.DataValueField = "CategoryID"; ddlist.DataBind(); }
If u r query is achieved,mark the thread as solved
Live and Let Live
Live and Let Live
![]() |
Similar Threads
- dropdownlist value doesnt get selected (ASP)
- create dynamic reports in asp.net (ASP.NET)
- create menu base on database data (VB.NET)
- ASP.NET / C# Dynamic Control (ASP.NET)
- Dynamic web pages? Which will exist? (IT Professionals' Lounge)
- Help With Datagrid RE: Creating and Saving DropDownList ReportsToID (C#)
Other Threads in the ASP.NET Forum
- Previous Thread: Asp.net behind code not correct
- Next Thread: Pass Windows User (domain\userid) to report url in ASCX page
| Thread Tools | Search this Thread |
.net 3.5 ajax alltypeofvideos appliances asp asp.net bc30451 beginner box browser businesslogiclayer button c# cac checkbox class commonfunctions control countryselector dataaccesslayer database datagrid datagridview datagridviewcheckbox datalist deployment development dgv dialog dropdownlist dropdownmenu dynamic dynamically edit embeddingactivexcontrol expose fileuploader fill findcontrol flash formatdecimal formview gridview gudi iis javascript list listbox login microsoft mouse mssql nameisnotdeclared news novell numerical opera panelmasterpagebuttoncontrols problem radio redirect registration relationaldatabases reportemail save schoolproject search security sessionvariables silverlight smartcard smoobjects software sql sql-server sqlserver2005 ssl suse textbox tracking treeview unauthorized validatedate validation vb.net video videos vista visualstudio vs2008 web webapplications webdevelopemnt webdevelopment webprogramming webservice wizard xsl youareanotmemberofthedebuggerusers





