473,796 Members | 2,669 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

System.Web.Http Exception: A DropDownList cannot have multiple items selected

I'm having such a problem with this DropDownList in a user control that is
posting back and throwing an error: System.Web.Http Exception: A
DropDownList cannot have multiple items selected

<ASP:DROPDOWNLI ST ID="lbCountries Wiz" ENABLEVIEWSTATE ="true" FONT-SIZE="8pt"
ONSELECTEDINDEX CHANGED="ddlQue ryProvinces"
AUTOPOSTBACK="T rue" RUNAT="server" WIDTH="150px"></ASP:DROPDOWNLIS T>
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here

If Not Page.IsPostBack Then

Dim tempItem3 As New System.Web.UI.W ebControls.List Item
tempItem3.Text = "Chad"
tempItem3.Value = "TD"
tempItem3.Selec ted = False
Me.lbCountriesW iz.Items.Insert (0, tempItem3)

Dim tempItem2 As New System.Web.UI.W ebControls.List Item
tempItem2.Text = "Bosnia and Herzegovina"
tempItem2.Value = "BA"
tempItem2.Selec ted = False
Me.lbCountriesW iz.Items.Insert (0, tempItem2)

Dim tempItem As New System.Web.UI.W ebControls.List Item
tempItem.Text = "|--None Selected"
tempItem.Value = "0"
tempItem.Select ed = False
lbCountriesWiz. Items.Insert(0, tempItem)

End If

End Sub

When a button in the same user control is pushed and then I reselect the
DropDownList, I don't get the error.

<ASP:BUTTON ID="btnAllCommu nities"
ONCLICK="btnPop ulateAllCommuni ties_OnClick" FONT-SIZE="8"
RUNAT="server" TEXT="All Communities" BORDERSTYLE="in set"></ASP:BUTTON>

Public Sub btnPopulateAllC ommunities_OnCl ick(ByVal sender As System.Object,
ByVal e As System.EventArg s) Handles btnAllCommuniti es.Click

'These simply fill some other listboxes

GetProvinces()
GetDistricts()
GetSubDistricts ()
GetCommunities( )

End Sub

When buttons (such as below) in the controling Page are pushed and then I
try to reselect the DropDownList, I get the error.

<ASP:BUTTON id="btn1" onclick="GetRep ort1_OnClick" RUNAT="server" TEXT="Get
report of" HEIGHT="20"
FONT-SIZE="10px"></ASP:BUTTON>

Sub GetReport1_OnCl ick(ByVal Sender As Object, ByVal e As System.EventArg s)

Try

dgSHA.Visible = False
dgShasSum.Visib le = False
dgCommunity.Vis ible = True
dgCommunitiesSu m.Visible = True
ShowButtons()


'pnlCommunities Buttons.Visible = True

Dim _sqlStmtR1 As String
_sqlStmtR1 = "SELECT * FROM vwCommunities WHERE countryID = '" &
CType(Page,
_default1).choo seAdminUnitsWiz 1.lbCountriesWi z.SelectedItem. Value & "' "

If ddlImpactLevel1 .SelectedItem.V alue <> "All" Then
_sqlStmtR1 = _sqlStmtR1 & " AND Impact = '" &
ddlImpactLevel1 .SelectedItem.V alue & "'"
End If
'_sqlStmtR1 = _sqlStmtR1 & " ORDER BY Community"

Dim myDataSetCommun ities1 As New DataSet
Dim myDataAdapterCo mmunities1 As New SqlDataAdapter( _sqlStmtR1,
connection1.con String)
myDataAdapterCo mmunities1.Fill (myDataSetCommu nities1,
"CommunitiesTmp 1")
dgCommunity.Dat aSource =
myDataSetCommun ities1.Tables(" CommunitiesTmp1 ")
dgCommunity.Dat aBind()

CommunitiesWizS qlSumStatement( 1)

Dim myDataSetCommun itiesSum As New DataSet
Dim myDataAdapterCo mmunitiesSum As New
SqlDataAdapter( _sqlStmtLbCommu nitiesWizSum, connection1.con String)
myDataAdapterCo mmunitiesSum.Fi ll(myDataSetCom munitiesSum,
"CommunitiesSum Tmp1")
dgCommunitiesSu m.DataSource =
myDataSetCommun itiesSum.Tables ("CommunitiesSu mTmp1")
dgCommunitiesSu m.DataBind()
RecordCount2.Te xt = ""
RecordCount3.Te xt = ""
RecordCount4.Te xt = ""
RecordCount5.Te xt = ""
RecordCount6.Te xt = ""

Dim RcdCount As Integer
Dim ResultCount As Integer
RcdCount =
myDataSetCommun ities1.Tables(" CommunitiesTmp1 ").Rows.Count.T oString()
ResultCount = RcdCount
RecordCount1.Te xt = RcdCount & " records"
RecordCountBott om.Text = RcdCount & " records"

Session("savedD ataGridSql") = _sqlStmtR1
Session("dgType ") = "Community"
Me.sortCriteria = "Community"
Me.sortDir = "ASC"
If Session("dgType ") = "Community" Then
pnlCommunitiesB uttons.Visible = True
pnlShasButtons. Visible = False
Else
pnlCommunitiesB uttons.Visible = False
pnlShasButtons. Visible = True
End If


Catch ex As Exception
ExceptionManage r.Publish(ex)
End Try
End Sub
Jul 25 '05 #1
1 6330
You've shown a lot of code, too much and too spread out to be too useful.
But the error speaks for itself, somewhere you are setting two selected
values to the dropdown and this isn't allowed. My guess is that it's
beeing set in the Page_Load and being set elsewhere on one of the many
button postbacks.... You'll simply need to debug and/or simplify your code
to get to the root of it.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"DC Gringo" <dc******@visio ntechnology.net > wrote in message
news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
I'm having such a problem with this DropDownList in a user control that is
posting back and throwing an error: System.Web.Http Exception: A
DropDownList cannot have multiple items selected

<ASP:DROPDOWNLI ST ID="lbCountries Wiz" ENABLEVIEWSTATE ="true"
FONT-SIZE="8pt" ONSELECTEDINDEX CHANGED="ddlQue ryProvinces"
AUTOPOSTBACK="T rue" RUNAT="server" WIDTH="150px"></ASP:DROPDOWNLIS T>
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here

If Not Page.IsPostBack Then

Dim tempItem3 As New System.Web.UI.W ebControls.List Item
tempItem3.Text = "Chad"
tempItem3.Value = "TD"
tempItem3.Selec ted = False
Me.lbCountriesW iz.Items.Insert (0, tempItem3)

Dim tempItem2 As New System.Web.UI.W ebControls.List Item
tempItem2.Text = "Bosnia and Herzegovina"
tempItem2.Value = "BA"
tempItem2.Selec ted = False
Me.lbCountriesW iz.Items.Insert (0, tempItem2)

Dim tempItem As New System.Web.UI.W ebControls.List Item
tempItem.Text = "|--None Selected"
tempItem.Value = "0"
tempItem.Select ed = False
lbCountriesWiz. Items.Insert(0, tempItem)

End If

End Sub

When a button in the same user control is pushed and then I reselect the
DropDownList, I don't get the error.

<ASP:BUTTON ID="btnAllCommu nities"
ONCLICK="btnPop ulateAllCommuni ties_OnClick" FONT-SIZE="8"
RUNAT="server" TEXT="All Communities" BORDERSTYLE="in set"></ASP:BUTTON>

Public Sub btnPopulateAllC ommunities_OnCl ick(ByVal sender As
System.Object, ByVal e As System.EventArg s) Handles
btnAllCommuniti es.Click

'These simply fill some other listboxes

GetProvinces()
GetDistricts()
GetSubDistricts ()
GetCommunities( )

End Sub

When buttons (such as below) in the controling Page are pushed and then I
try to reselect the DropDownList, I get the error.

<ASP:BUTTON id="btn1" onclick="GetRep ort1_OnClick" RUNAT="server"
TEXT="Get report of" HEIGHT="20"
FONT-SIZE="10px"></ASP:BUTTON>

Sub GetReport1_OnCl ick(ByVal Sender As Object, ByVal e As
System.EventArg s)

Try

dgSHA.Visible = False
dgShasSum.Visib le = False
dgCommunity.Vis ible = True
dgCommunitiesSu m.Visible = True
ShowButtons()


'pnlCommunities Buttons.Visible = True

Dim _sqlStmtR1 As String
_sqlStmtR1 = "SELECT * FROM vwCommunities WHERE countryID = '"
& CType(Page,
_default1).choo seAdminUnitsWiz 1.lbCountriesWi z.SelectedItem. Value & "' "

If ddlImpactLevel1 .SelectedItem.V alue <> "All" Then
_sqlStmtR1 = _sqlStmtR1 & " AND Impact = '" &
ddlImpactLevel1 .SelectedItem.V alue & "'"
End If
'_sqlStmtR1 = _sqlStmtR1 & " ORDER BY Community"

Dim myDataSetCommun ities1 As New DataSet
Dim myDataAdapterCo mmunities1 As New SqlDataAdapter( _sqlStmtR1,
connection1.con String)
myDataAdapterCo mmunities1.Fill (myDataSetCommu nities1,
"CommunitiesTmp 1")
dgCommunity.Dat aSource =
myDataSetCommun ities1.Tables(" CommunitiesTmp1 ")
dgCommunity.Dat aBind()

CommunitiesWizS qlSumStatement( 1)

Dim myDataSetCommun itiesSum As New DataSet
Dim myDataAdapterCo mmunitiesSum As New
SqlDataAdapter( _sqlStmtLbCommu nitiesWizSum, connection1.con String)
myDataAdapterCo mmunitiesSum.Fi ll(myDataSetCom munitiesSum,
"CommunitiesSum Tmp1")
dgCommunitiesSu m.DataSource =
myDataSetCommun itiesSum.Tables ("CommunitiesSu mTmp1")
dgCommunitiesSu m.DataBind()
RecordCount2.Te xt = ""
RecordCount3.Te xt = ""
RecordCount4.Te xt = ""
RecordCount5.Te xt = ""
RecordCount6.Te xt = ""

Dim RcdCount As Integer
Dim ResultCount As Integer
RcdCount =
myDataSetCommun ities1.Tables(" CommunitiesTmp1 ").Rows.Count.T oString()
ResultCount = RcdCount
RecordCount1.Te xt = RcdCount & " records"
RecordCountBott om.Text = RcdCount & " records"

Session("savedD ataGridSql") = _sqlStmtR1
Session("dgType ") = "Community"
Me.sortCriteria = "Community"
Me.sortDir = "ASC"
If Session("dgType ") = "Community" Then
pnlCommunitiesB uttons.Visible = True
pnlShasButtons. Visible = False
Else
pnlCommunitiesB uttons.Visible = False
pnlShasButtons. Visible = True
End If


Catch ex As Exception
ExceptionManage r.Publish(ex)
End Try
End Sub

Jul 26 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
10773
by: dhnriverside | last post by:
Hi guys Still having a problem with this dropdownlist. Basically, I've got 4. The first 2 work fine, then my code crashes on the 3rd. ddlEndTimeHour.Items.FindByValue(endTime).Selected = true; Where endTime is a string containing "15".
2
1689
by: DC Gringo | last post by:
I'm having such a problem with this DropDownList in a user control that is posting back and throwing an error: System.Web.HttpException: A DropDownList cannot have multiple items selected <ASP:DROPDOWNLIST ID="lbCountriesWiz" ENABLEVIEWSTATE="true" FONT-SIZE="8pt" ONSELECTEDINDEXCHANGED="ddlQueryProvinces" AUTOPOSTBACK="True" RUNAT="server" WIDTH="150px"></ASP:DROPDOWNLIST> Private Sub Page_Load(ByVal sender As System.Object, ByVal...
1
7422
by: g | last post by:
I have a user control that contains a dropdownlist. Using a public property, I can get the selected item. However, I am unsure of how to use that same public property to set the selected item. Here's my code: private string m_item = ""; public string Item { get {
10
6393
by: ads | last post by:
hi, after binding the dropdownlist to a datasource, ive experience this error "Cannot have multiple items selected in a dropdownlist" after using the code: dropdownlist.items.findbyvalue("value").selected = true I didnt specify any selected item in the dropdownlist during binding to the datasource. I use dropdownlist.clearselection() but still error occurs. I need information on this. Thanks. Ads
1
10399
by: Ben | last post by:
I have a formview with a few dropdownlists (software version, database version, etc). When a software version is selected, the database version dropdownlist updates itself accordingly. When in edit mode, everything works fine - the selected value in each list defaults to the value from the database record (selectedvalue=bind...). However, in insert mode (insertitem), it is not working. I pass in a value on the query string that I would...
2
242
by: Lou Civitella | last post by:
I have two drop down list boxes on my asp page. The boxes store a country value on my page. They are filled by code during the load event and then I set their values in code from a table on a SQL server. If the values are the same then all is OK but if the values happen to be different I get this error Cannot have multiple items selected in a DropDownList. I cannot fiugre out why this keeps happening. I have two other DropDownList boxes...
4
6140
by: rn5a | last post by:
I am binding a DropDownList with records existing in a database table. I want to add an extra item *SELECT COMPANY* at index 0 so that by default, it gets selected. This is how I tried it but the extra item just doesn't get added to the DropDownList: ============================================= <script runat="server"> Sub Page_Load(..........) Dim dSet As DataSet Dim sqlConn As SqlConnection
2
15254
by: =?Utf-8?B?S3Jpc2huYQ==?= | last post by:
Hi, I am devloping one web application using .net framework 2.0.One page has 7 dropdown list control.When i update the values first bind the values to the drop down llist then selected text using findbytext method.I got the following error ERROR: Cannot have multiple items selected in a DropDownList. Coding is below
2
3325
by: mylog | last post by:
Hi I am having a problem of getting the value from the dynamically generated table and dropdownlist. What I am facing is, I have created a table in the aspx page and now I need to add values to the the cells of the table respectively which I have done easily but the problem is when I add the dynamically generated dropdownlist to the cell I cannot read the value from the dropdownlist. For adding the dropdownlist in the cell I have done the...
0
9525
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10452
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10221
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9050
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7546
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5440
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.