473,383 Members | 1,735 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,383 software developers and data experts.

System.Web.HttpException: 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.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 e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

If Not Page.IsPostBack Then

Dim tempItem3 As New System.Web.UI.WebControls.ListItem
tempItem3.Text = "Chad"
tempItem3.Value = "TD"
tempItem3.Selected = False
Me.lbCountriesWiz.Items.Insert(0, tempItem3)

Dim tempItem2 As New System.Web.UI.WebControls.ListItem
tempItem2.Text = "Bosnia and Herzegovina"
tempItem2.Value = "BA"
tempItem2.Selected = False
Me.lbCountriesWiz.Items.Insert(0, tempItem2)

Dim tempItem As New System.Web.UI.WebControls.ListItem
tempItem.Text = "|--None Selected"
tempItem.Value = "0"
tempItem.Selected = 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="btnAllCommunities"
ONCLICK="btnPopulateAllCommunities_OnClick" FONT-SIZE="8"
RUNAT="server" TEXT="All Communities" BORDERSTYLE="inset"></ASP:BUTTON>

Public Sub btnPopulateAllCommunities_OnClick(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnAllCommunities.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="GetReport1_OnClick" RUNAT="server" TEXT="Get
report of" HEIGHT="20"
FONT-SIZE="10px"></ASP:BUTTON>

Sub GetReport1_OnClick(ByVal Sender As Object, ByVal e As System.EventArgs)

Try

dgSHA.Visible = False
dgShasSum.Visible = False
dgCommunity.Visible = True
dgCommunitiesSum.Visible = True
ShowButtons()


'pnlCommunitiesButtons.Visible = True

Dim _sqlStmtR1 As String
_sqlStmtR1 = "SELECT * FROM vwCommunities WHERE countryID = '" &
CType(Page,
_default1).chooseAdminUnitsWiz1.lbCountriesWiz.Sel ectedItem.Value & "' "

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

Dim myDataSetCommunities1 As New DataSet
Dim myDataAdapterCommunities1 As New SqlDataAdapter(_sqlStmtR1,
connection1.conString)
myDataAdapterCommunities1.Fill(myDataSetCommunitie s1,
"CommunitiesTmp1")
dgCommunity.DataSource =
myDataSetCommunities1.Tables("CommunitiesTmp1")
dgCommunity.DataBind()

CommunitiesWizSqlSumStatement(1)

Dim myDataSetCommunitiesSum As New DataSet
Dim myDataAdapterCommunitiesSum As New
SqlDataAdapter(_sqlStmtLbCommunitiesWizSum, connection1.conString)
myDataAdapterCommunitiesSum.Fill(myDataSetCommunit iesSum,
"CommunitiesSumTmp1")
dgCommunitiesSum.DataSource =
myDataSetCommunitiesSum.Tables("CommunitiesSumTmp1 ")
dgCommunitiesSum.DataBind()
RecordCount2.Text = ""
RecordCount3.Text = ""
RecordCount4.Text = ""
RecordCount5.Text = ""
RecordCount6.Text = ""

Dim RcdCount As Integer
Dim ResultCount As Integer
RcdCount =
myDataSetCommunities1.Tables("CommunitiesTmp1").Ro ws.Count.ToString()
ResultCount = RcdCount
RecordCount1.Text = RcdCount & " records"
RecordCountBottom.Text = RcdCount & " records"

Session("savedDataGridSql") = _sqlStmtR1
Session("dgType") = "Community"
Me.sortCriteria = "Community"
Me.sortDir = "ASC"
If Session("dgType") = "Community" Then
pnlCommunitiesButtons.Visible = True
pnlShasButtons.Visible = False
Else
pnlCommunitiesButtons.Visible = False
pnlShasButtons.Visible = True
End If


Catch ex As Exception
ExceptionManager.Publish(ex)
End Try
End Sub
Jul 25 '05 #1
1 6285
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******@visiontechnology.net> wrote in message
news:%2***************@TK2MSFTNGP09.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.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 e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

If Not Page.IsPostBack Then

Dim tempItem3 As New System.Web.UI.WebControls.ListItem
tempItem3.Text = "Chad"
tempItem3.Value = "TD"
tempItem3.Selected = False
Me.lbCountriesWiz.Items.Insert(0, tempItem3)

Dim tempItem2 As New System.Web.UI.WebControls.ListItem
tempItem2.Text = "Bosnia and Herzegovina"
tempItem2.Value = "BA"
tempItem2.Selected = False
Me.lbCountriesWiz.Items.Insert(0, tempItem2)

Dim tempItem As New System.Web.UI.WebControls.ListItem
tempItem.Text = "|--None Selected"
tempItem.Value = "0"
tempItem.Selected = 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="btnAllCommunities"
ONCLICK="btnPopulateAllCommunities_OnClick" FONT-SIZE="8"
RUNAT="server" TEXT="All Communities" BORDERSTYLE="inset"></ASP:BUTTON>

Public Sub btnPopulateAllCommunities_OnClick(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
btnAllCommunities.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="GetReport1_OnClick" RUNAT="server"
TEXT="Get report of" HEIGHT="20"
FONT-SIZE="10px"></ASP:BUTTON>

Sub GetReport1_OnClick(ByVal Sender As Object, ByVal e As
System.EventArgs)

Try

dgSHA.Visible = False
dgShasSum.Visible = False
dgCommunity.Visible = True
dgCommunitiesSum.Visible = True
ShowButtons()


'pnlCommunitiesButtons.Visible = True

Dim _sqlStmtR1 As String
_sqlStmtR1 = "SELECT * FROM vwCommunities WHERE countryID = '"
& CType(Page,
_default1).chooseAdminUnitsWiz1.lbCountriesWiz.Sel ectedItem.Value & "' "

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

Dim myDataSetCommunities1 As New DataSet
Dim myDataAdapterCommunities1 As New SqlDataAdapter(_sqlStmtR1,
connection1.conString)
myDataAdapterCommunities1.Fill(myDataSetCommunitie s1,
"CommunitiesTmp1")
dgCommunity.DataSource =
myDataSetCommunities1.Tables("CommunitiesTmp1")
dgCommunity.DataBind()

CommunitiesWizSqlSumStatement(1)

Dim myDataSetCommunitiesSum As New DataSet
Dim myDataAdapterCommunitiesSum As New
SqlDataAdapter(_sqlStmtLbCommunitiesWizSum, connection1.conString)
myDataAdapterCommunitiesSum.Fill(myDataSetCommunit iesSum,
"CommunitiesSumTmp1")
dgCommunitiesSum.DataSource =
myDataSetCommunitiesSum.Tables("CommunitiesSumTmp1 ")
dgCommunitiesSum.DataBind()
RecordCount2.Text = ""
RecordCount3.Text = ""
RecordCount4.Text = ""
RecordCount5.Text = ""
RecordCount6.Text = ""

Dim RcdCount As Integer
Dim ResultCount As Integer
RcdCount =
myDataSetCommunities1.Tables("CommunitiesTmp1").Ro ws.Count.ToString()
ResultCount = RcdCount
RecordCount1.Text = RcdCount & " records"
RecordCountBottom.Text = RcdCount & " records"

Session("savedDataGridSql") = _sqlStmtR1
Session("dgType") = "Community"
Me.sortCriteria = "Community"
Me.sortDir = "ASC"
If Session("dgType") = "Community" Then
pnlCommunitiesButtons.Visible = True
pnlShasButtons.Visible = False
Else
pnlCommunitiesButtons.Visible = False
pnlShasButtons.Visible = True
End If


Catch ex As Exception
ExceptionManager.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
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 =...
2
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 ...
1
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. ...
10
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:...
1
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...
2
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...
4
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...
2
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...
2
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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.