By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,498 Members | 1,558 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,498 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Nov 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

Nov 19 '05 #2

P: n/a
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

Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.