CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums




Can Reply:  No Members Can Edit: No Online: Yes
Zone: > NEWSGROUP > Asp.Net Forum > general_asp.net.faq_frequently_asked_questions Tags:
Item Type: NewsGroup Date Entered: 5/3/2006 10:41:40 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
NR
XPoints: N/A Replies: 10 Views: 61 Favorited: 0 Favorite
11 Items, 1 Pages 1 |< << Go >> >|
ranganh
Asp.Net User
ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."5/3/2006 10:41:40 AM

0

Hi,

You may receive the error "Cannot have multiple items selected in a DropDownList." when trying to set a value selected in an ASP.NET Dropdownlist.

This error specifically occurs if you are trying to execute a similar code as follows:-



DropDownList1.Items.FindByValue("3").Selected = true;

(or)

DropDownList1.Items.FindByText("Sports").Selected = true;

This error doesnt occur if you try to use

DropDownList1.SelectedIndex = 3;
or
DropDownList1.SelectedItem.Value = "3"; (Wrong way of implementation. But people use this)


The resolution is that, you just have to mention DropDownList1.ClearSelection(); before using D
ropDownList1.Items.FindByValue("3").Selected = true;

The correct step is as below:-

DropDownList1.ClearSelection();
DropDownList1.Items.FindByValue("3").Selected = true;

or

DropDownList1.ClearSelection();
DropDownList1.Items.FindByText("Sports").Selected = true;

Thanks.


regards,
Harish

http://geekswithblogs.net/ranganh
PeterBrunone
Asp.Net User
Re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."5/3/2006 7:39:30 PM

0

With 1.1, you can just say

DropDownList1.SelectedValue = "sports"

instead.

Of course you've always been able to do this with ELB, and the selection is cleared for you automatically :)


Peter Brunone
MS MVP, ASP.NET
Founder, EasyListBox.com
Do the impossible, and go home early.
Jessy
Asp.Net User
File changed in different computers5/4/2006 3:21:48 PM

0

Hi expert. I wrote a program using asp.net. I have run this program for serveral months and everything is fine. Later on  I changed a new computer, the program still ran but the printout has changed significantly no matter how I changed the setting and codes. What caused the problem? Also I copied this file to the other computer and it worked fine at that time, but one month later, I tried to run the program again, it doesn't work any more and it gives me a bunch of  web system errors. These two computers are new ones. As normal, it shouldn't happen, but it did. I really don't know what's wrong with them. Appreciate for your kindly help!
Nitin Pawar
Asp.Net User
Re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."4/16/2007 1:26:37 PM

0

Hi All,

I am having same problem but with different code.

I have 3 dropdown box, named ddDay, ddMonth, ddYear.
In the page i am using javascript for date validation using Custom Validation Control

Javascript
=========================================================

function findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function getDDValue(idDD)
{
    var objDD = findObj(idDD); // findObj returns object from id
    return objDD.options[objDD.selectedIndex].value;
}

function jsCheckDate(sender, args)
{
    var ddDay = getDDValue("<%=ddDay.ClientID%>");
    var ddMonth = getDDValue("<%=ddMonth.ClientID%>");
    var ddYear = getDDValue("<%=ddYear.ClientID%>");
 
    var strDate = ddDay + "-" + ddMonth + "-" + ddYear;

 if (isDate(strDate, "d-MMM-y")) // isDate is function to check date
    {
        args.IsValid = true;
        return;
    }else {
        args.IsValid = false;
        return;
    }
}

Code Behind (On pageload)
=========================================================

       If Not IsPostBack Then

            ddDay.Items.Add(New ListItem("-- Day --", ""))
            ddDay.SelectedIndex = 0
            For i As Integer = 1 To 31
                ddDay.Items.Add(i)
            Next

            ddMonth.Items.Add(New ListItem("-- Month --", ""))
            ddMonth.SelectedIndex = 0
            For i As Integer = 1 To 12
                ddMonth.Items.Add(New ListItem(MonthName(i), MonthName(i, True)))
            Next

            ddYear.Items.Add(New ListItem("-- Year --", ""))
            ddYear.SelectedIndex = 0
            For i As Integer = (Year(Now) - 50) To (Year(Now) - 15)
                ddYear.Items.Add(i)
            Next

        End If

 

Error Page
=========================================================

Server Error in '/Quincy' Application.

Cannot have multiple items selected in a DropDownList.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Cannot have multiple items selected in a DropDownList.

Source Error:

Line 26:     var ddDay = getDDValue("<%=ddDay.ClientID%>");
Line 27:     var ddMonth = getDDValue("<%=ddMonth.ClientID%>");
Line 28:     var ddYear = getDDValue("<%=ddYear.ClientID%>");
Line 29:   
Line 30:     var strDate = ddDay + "-" + ddMonth + "-" + ddYear;

Source File: C:\Inetpub\wwwroot\Quincy\Consultants\Profile_Main.aspx    Line: 28

Stack Trace:

[HttpException (0x80004005): Cannot have multiple items selected in a DropDownList.]
   System.Web.UI.WebControls.DropDownList.VerifyMultiSelect() +107
   System.Web.UI.WebControls.ListControl.RenderContents(HtmlTextWriter writer) +1774854
   System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) +29
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +25
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +121
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22
   ASP.consultants_profile_main_aspx.__RenderContent1(HtmlTextWriter __w, Control parameterContainer) in C:\Inetpub\wwwroot\Quincy\Consultants\Profile_Main.aspx:28
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +2065851
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +24
   System.Web.UI.Control.Render(HtmlTextWriter writer) +7
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +25
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +121
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22
   ASP.consultants_consultant_master.__RendertdContent(HtmlTextWriter __w, Control parameterContainer) in C:\Inetpub\wwwroot\Quincy\Consultants\Consultant.master:61
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +2065851
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +24
   System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +29
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +25
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +121
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +130
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +24
   System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +59
   System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output) +68
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +25
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +121
   System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) +37
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +130
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +24
   System.Web.UI.Control.Render(HtmlTextWriter writer) +7
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +25
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +121
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +130
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +24
   System.Web.UI.Page.Render(HtmlTextWriter writer) +26
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +25
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +121
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1896


Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42

Nitin Pawar
Asp.Net User
Re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."4/17/2007 9:22:11 AM

0

Hey guys above problem of mine got solved.

PeterBrunone
Asp.Net User
Re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."4/17/2007 3:38:07 PM

0

So what was your solution?
Peter Brunone
MS MVP, ASP.NET
Founder, EasyListBox.com
Do the impossible, and go home early.
kennsterdude
Asp.Net User
Re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."4/24/2007 1:49:17 PM

0

Hello:

I am having a similar issue whereby identical code & database running on two separate machines works on one and not the other. In my case, I upgrade a DNN 4.4.1 install to DNN 4.5.1 on two separate machines running an identical stack of software (I am working on a modification of the core store module of DotNetNuke for a client of mine). The module uses some MVP architecture principals and is very sophisticated, so sophisticated in fact that sometimes it is very hard to trace though to find the offending code.

 I also get a similar stack trace : thoroughly incomprehensible for me.

I read somewhere this may have to do with required field validators: and there are RFV's in the module, which are selectively enabled based upon internationalization options.

The main point I wanted to make is that of two identical stacks of software, only one exhibits this problem.

 One more note: Asp.net 2.0 with ajax extensions installed on the machine that doesn't work.

 

Subhadip
Asp.Net User
Re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."9/25/2007 10:57:15 AM

0

You cannot have more than 1 item selected in the dropdown at the same time, hence the current selected item should be made selected  = false and then make the item you want to be selected as true

The solution to the above error is:

First...

/// Make the current item deselected

dropdownInstance.SelectedItem.Selected = false;

then the following piece:

dropdownInstance.FindByValue("xyz").Selected = true;

or

dropdownInstance.FindByValue("xyz").Selected = false;

Let me know if this solves the issue.

 

Thanks,

Subhadip

PeterBrunone
Asp.Net User
Re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."9/25/2007 1:52:01 PM

0

Welcome to the thread!

If you don't appear to be setting multiple items to Selected = True, then you may have another problem.  Recently I came across people who would create new ListItem objects and try to add them to multiple list controls, or add them multiple times without instantiating a new ListItem each time.  This can lead to multiple selected items, and trigger the error mentioned here.
 


Peter Brunone
MS MVP, ASP.NET
Founder, EasyListBox.com
Do the impossible, and go home early.
ashwani2kumar
Asp.Net User
Re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."10/10/2007 9:49:12 AM

0

Hello

 So i simple words you want to pass the value from ddl to SQL query hmm ok...

here :

Your code...

Dim cmd12 As New SqlCommand("SELECT Cgrade from access_control.dbo.table_cadre" & _
" WHERE cadre = '" & ddl_cadre.SelectedItem.Text & "' ", consql)

cmd12.Connection.Open()
reader = cmd12.ExecuteReader()
ddl_cgrade.DataSource = reader
ddl_cgrade.DataTextField = "Cgrade"
ddl_cgrade.DataBind()
reader.Close()
cmd12.Connection.Close()

follow my code :
Dim CMD as SQLCommand

Cmd.CommandText = "Select Cgrade from access_control.dbo.table_cadre" & _
"Where cadre='" & ddl_cadre.SelectedValue.ToString & "'", consql

cmd.Connection.Open()
reader = cmd.ExecuteReader()
ddl_cgrade.DataSource = reader
ddl_cgrade.DataTextField = "Cgrade"
ddl_cgrade.DataBind()
reader.Close()
cmd.Connection.Close()

 

ashwani


ashwnai
sandeeppandana
Asp.Net User
Re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."10/15/2007 4:21:43 AM

0

Any way why do you want to select two items from the list. Can you please give a scenario where this is possible?

Thanx 

11 Items, 1 Pages 1 |< << Go >> >|


Free Download:




   
  Privacy | Contact Us
All Times Are GMT