Saturday, April 30, 2011

ASP.NET Drop down list and strongly typed DataTable

I had code where I populate the contents of an ASP.NET DropDownList with a strongly typed DataTable returned from an ASP.NET web service. In this code I bound the DataTable to the DataSource of the DropDownList and did a DataBind() in the Page_Load() method. This worked perfectly fine on my local box.

However, when I loaded up the ASP.NET page in the production data center, I got:

System.Web.HttpException: A
DropDownList cannot have multiple items selected

To solve this problem, after I bound the DataTable to the DropDownList, I iterated through each ListItem and set its Selected property to false:

foreach (ListItem myItem in myDropDownList)
{
myItem.Selected = false;
}

2 comments:

11x17MarketingDepartment said...

Hello, just dropping a note to let you know that we carry many professional products to meet your office needs for storage and presentation of your drawings. At 11x17.com you can find many high quality products at great prices.
Give us a call if you have any questions at 903-541-0100 or email us at sales@11x17.com.
Thanks for your time and consideration.

Nick said...

Nice! post its really informative...

Software Product Development Services: - Ampere is a fast growing outsourced software product engineering company focused on helping software companies create innovative products for the next generation. Headquartered in India, Ampere has proven expertise and a deep domain understanding of technology to deliver software engineering services such as software product development (web/non web), product migration, software testing and custom application development maintenance to enterprises spread across the globe.