473,378 Members | 1,391 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Dropdownlist is not accepting new items when added dynamically

On adding items in it ,shows an error: "Dropdownlist does not allow multiple selection."
But when i tries to print the selected item it shows null exception.
Dec 24 '10 #1
6 1770
Could you include some of your code as an example?
Dec 27 '10 #2
Expand|Select|Wrap|Line Numbers
  1.  
  2. using System;
  3. using System.Collections;
  4. using System.Configuration;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Web;
  8. using System.Web.Security;
  9. using System.Web.UI;
  10. using System.Web.UI.HtmlControls;
  11. using System.Web.UI.WebControls;
  12. using System.Web.UI.WebControls.WebParts;
  13. using System.Xml.Linq;
  14.  
  15. public partial class Expt : System.Web.UI.Page
  16. {
  17.     protected void Page_Load(object sender, EventArgs e)
  18.     {
  19.  
  20.  
  21.     }
  22.     protected void Bttnadd_Click(object sender, EventArgs e)
  23.     {
  24.  
  25.        DropDownList11.Items.Add(ListBox1.SelectedItem);
  26.         ListBox1.Items.Remove(ListBox1.SelectedItem);
  27.  
  28.  
  29.     }
  30.  
Dec 30 '10 #3
could you provide the page too, so I can see what the code behind is working with?
Dec 30 '10 #4
Please check the attached files
Attached Files
File Type: txt Expt.aspx.txt (1.1 KB, 278 views)
File Type: txt Expt.aspx.cs.txt (686 Bytes, 294 views)
Dec 31 '10 #5
By default the first item of a dropdown is selected. try setting the selectedindex of the dropdown to -1 before adding the new item...

protected void bttnaddck_Click(object sender, EventArgs e)
{
DropDownList1.SelectedIndex = -1;
DropDownList1.Items.Add(ListBox1.SelectedItem);
ListBox1.Items.Remove(ListBox1.SelectedItem);
}
Dec 31 '10 #6
U try to print the selected item it will show Null Exception error why so?
Jan 1 '11 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: m_evergreen | last post by:
I have a drop down which is pulling its values from a table, populated by database which is behaving very strangely. If the browser page is refreshed it becomes empty and will never repopulate. ...
1
by: Stanley J Mroczek | last post by:
I am trying to load a dropdownlist in VB when the edit is clicked in a datagrid. How do i call Sub loaddd to load the dropdownlist <asp:TemplateColumn runat="server" HeaderText="Id Type Option"...
3
by: Jigar Mehta | last post by:
Hye, This is Jigar mehta from India. I have made one application that adds dynamic menu items from the database. Each menu item has one ID and menu item's text is coming from the database. Now, I...
7
by: who be dat? | last post by:
I need some help here. I'm creating a list on a page where the list is created from a dataset with two tables linked with a datarelation. The first table is a list of groups while the second...
0
by: fwirtanen | last post by:
I am building a custom composite control consisting of two drop downs, with parent/child dependancy. The child dropdownlist is updated through client callback when the parent index changes. ...
5
by: Dennis Fazekas | last post by:
Greetings, I am creating a web form which will all the user to add an unlimited number of email addresses. Basically I have 3 buttons, "Add Another Email", "-" to remove, and a "Save" button....
1
by: Paul Aspinall | last post by:
Hi Is there a way of Preventing DropDownList from Dimming when disabled?? Thanks
6
by: Bjorn Sagbakken | last post by:
Hello In VS2005: I am adding buttons and textboxes dynamically into a table, that also dynamically expands. So far, so good, actually very nice. But I am having trouble starting the desired...
1
by: SubashiniKumaar | last post by:
how to copy dropdownlist selected items to another dropdownlist in Asp.net using C# codings
1
by: nse111 | last post by:
Is it possible to have a Session variable as an array in PHP where, that array gets values added to it dynamically? Im trying to create a inquiry cart where the product ids of all the items...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.