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

dropdownlist multiple selection problem

P: n/a
ads
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
Feb 13 '06 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Can we see your complete code? I'm not familiar with ClearSelection (don't
see it in the docs right now for some reason??)

Karl
--
http://www.openmymind.net/

"ads" <ad*@discussions.microsoft.com> wrote in message
news:BC**********************************@microsof t.com...
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

Feb 13 '06 #2

P: n/a
ads
//build the datasource of the 2 dropdownlists on page load

if(!ispostback)
{
for (int i = DateTime.Now.Year; i > DateTime.Now.Year - 50; i--)
{
ListItem li = new ListItem(i.ToString(), i.ToString());
ddlYrJoined.Items.Add(li);
ddlYrLeft.Items.Add(li);

}
ddlYrLeft.Items.Insert(0, "SELECT");
ddlYrJoined.Items.Insert(0,"SELECT");
}

//on a separate function

ddlYrJoined.Items.FindByValue(dr["yrstart"].ToString()).Selected = true;

//where dr["yrstart"].ToString() is a datareader getting its values from a
database

"Karl Seguin [MVP]" wrote:
Can we see your complete code? I'm not familiar with ClearSelection (don't
see it in the docs right now for some reason??)

Karl
--
http://www.openmymind.net/

"ads" <ad*@discussions.microsoft.com> wrote in message
news:BC**********************************@microsof t.com...
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


Feb 14 '06 #3

P: n/a
Is the separate function also called when !ispostback? You had also
mentioned ClearSelection() but I don't see that anywhere..

KArl

--
http://www.openmymind.net/

"ads" <ad*@discussions.microsoft.com> wrote in message
news:3C**********************************@microsof t.com...
//build the datasource of the 2 dropdownlists on page load

if(!ispostback)
{
for (int i = DateTime.Now.Year; i > DateTime.Now.Year - 50; i--)
{
ListItem li = new ListItem(i.ToString(), i.ToString());
ddlYrJoined.Items.Add(li);
ddlYrLeft.Items.Add(li);

}
ddlYrLeft.Items.Insert(0, "SELECT");
ddlYrJoined.Items.Insert(0,"SELECT");
}

//on a separate function

ddlYrJoined.Items.FindByValue(dr["yrstart"].ToString()).Selected = true;

//where dr["yrstart"].ToString() is a datareader getting its values from a
database

"Karl Seguin [MVP]" wrote:
Can we see your complete code? I'm not familiar with ClearSelection
(don't
see it in the docs right now for some reason??)

Karl
--
http://www.openmymind.net/

"ads" <ad*@discussions.microsoft.com> wrote in message
news:BC**********************************@microsof t.com...
> 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


Feb 14 '06 #4

P: n/a
ads
yes.the separate function is called when !ispostback too. Heres the complete
code:

if (!IsPostBack)
{
if (Request.QueryString["id"]!= null)
{
BindDDL();

LoadSelectedAffiliation(int.Parse(Request.QueryStr ing["id"].ToString()));
}

}

private void LoadSelectedAffiliation(int id)
{
SqlDataReader dr =
Microsoft.ApplicationBlocks.Data.SqlHelper.Execute Reader(System.Configuration.ConfigurationSettings. AppSettings["connectionstring"],
CommandType.Text, "select * from jbaffiliates where affiliateid=" + id);
ddlYrJoined.ClearSelection();
ddlYrLeft.ClearSelection();
while (dr.Read())
{
orgname.Text = dr["orgname"].ToString();
orgloc.Text = dr["orglocation"].ToString();
ddlYrJoined.Items.FindByValue(dr["yrstart"].ToString()).Selected
= true;
ddlYrLeft.Items.FindByValue(dr["yrend"].ToString()).Selected =
true;
position.Text = dr["highestpositiontitle"].ToString();
responsibilities.Text = dr["responsibilities"].ToString();
}
dr.Close();
}

private void BindDDL()
{
for (int i = DateTime.Now.Year; i > DateTime.Now.Year - 50; i--)
{
ListItem li = new ListItem(i.ToString(), i.ToString());
ddlYrJoined.Items.Add(li);
ddlYrLeft.Items.Add(li);

}
ddlYrLeft.Items.Insert(0, "SELECT");
ddlYrJoined.Items.Insert(0,"SELECT");
}
"Karl Seguin [MVP]" wrote:
Is the separate function also called when !ispostback? You had also
mentioned ClearSelection() but I don't see that anywhere..

KArl

--
http://www.openmymind.net/

"ads" <ad*@discussions.microsoft.com> wrote in message
news:3C**********************************@microsof t.com...
//build the datasource of the 2 dropdownlists on page load

if(!ispostback)
{
for (int i = DateTime.Now.Year; i > DateTime.Now.Year - 50; i--)
{
ListItem li = new ListItem(i.ToString(), i.ToString());
ddlYrJoined.Items.Add(li);
ddlYrLeft.Items.Add(li);

}
ddlYrLeft.Items.Insert(0, "SELECT");
ddlYrJoined.Items.Insert(0,"SELECT");
}

//on a separate function

ddlYrJoined.Items.FindByValue(dr["yrstart"].ToString()).Selected = true;

//where dr["yrstart"].ToString() is a datareader getting its values from a
database

"Karl Seguin [MVP]" wrote:
Can we see your complete code? I'm not familiar with ClearSelection
(don't
see it in the docs right now for some reason??)

Karl
--
http://www.openmymind.net/

"ads" <ad*@discussions.microsoft.com> wrote in message
news:BC**********************************@microsof t.com...
> 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


Feb 15 '06 #5

P: n/a
well that clears that up. I didn't think you were setting multiple values.
You can't do that in a dropdownbox, use a listbox instead.

Karl

--
http://www.openmymind.net/

"ads" <ad*@discussions.microsoft.com> wrote in message
news:D0**********************************@microsof t.com...
yes.the separate function is called when !ispostback too. Heres the
complete
code:

if (!IsPostBack)
{
if (Request.QueryString["id"]!= null)
{
BindDDL();

LoadSelectedAffiliation(int.Parse(Request.QueryStr ing["id"].ToString()));
}

}

private void LoadSelectedAffiliation(int id)
{
SqlDataReader dr =
Microsoft.ApplicationBlocks.Data.SqlHelper.Execute Reader(System.Configuration.ConfigurationSettings. AppSettings["connectionstring"],
CommandType.Text, "select * from jbaffiliates where affiliateid=" + id);
ddlYrJoined.ClearSelection();
ddlYrLeft.ClearSelection();
while (dr.Read())
{
orgname.Text = dr["orgname"].ToString();
orgloc.Text = dr["orglocation"].ToString();

ddlYrJoined.Items.FindByValue(dr["yrstart"].ToString()).Selected
= true;
ddlYrLeft.Items.FindByValue(dr["yrend"].ToString()).Selected =
true;
position.Text = dr["highestpositiontitle"].ToString();
responsibilities.Text = dr["responsibilities"].ToString();
}
dr.Close();
}

private void BindDDL()
{
for (int i = DateTime.Now.Year; i > DateTime.Now.Year - 50; i--)
{
ListItem li = new ListItem(i.ToString(), i.ToString());
ddlYrJoined.Items.Add(li);
ddlYrLeft.Items.Add(li);

}
ddlYrLeft.Items.Insert(0, "SELECT");
ddlYrJoined.Items.Insert(0,"SELECT");
}
"Karl Seguin [MVP]" wrote:
Is the separate function also called when !ispostback? You had also
mentioned ClearSelection() but I don't see that anywhere..

KArl

--
http://www.openmymind.net/

"ads" <ad*@discussions.microsoft.com> wrote in message
news:3C**********************************@microsof t.com...
> //build the datasource of the 2 dropdownlists on page load
>
> if(!ispostback)
> {
> for (int i = DateTime.Now.Year; i > DateTime.Now.Year - 50; i--)
> {
> ListItem li = new ListItem(i.ToString(), i.ToString());
> ddlYrJoined.Items.Add(li);
> ddlYrLeft.Items.Add(li);
>
> }
> ddlYrLeft.Items.Insert(0, "SELECT");
> ddlYrJoined.Items.Insert(0,"SELECT");
> }
>
> //on a separate function
>
> ddlYrJoined.Items.FindByValue(dr["yrstart"].ToString()).Selected =
> true;
>
> //where dr["yrstart"].ToString() is a datareader getting its values
> from a
> database
>
> "Karl Seguin [MVP]" wrote:
>
>> Can we see your complete code? I'm not familiar with ClearSelection
>> (don't
>> see it in the docs right now for some reason??)
>>
>> Karl
>> --
>> http://www.openmymind.net/
>>
>>
>>
>> "ads" <ad*@discussions.microsoft.com> wrote in message
>> news:BC**********************************@microsof t.com...
>> > 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
>>
>>
>>


Feb 15 '06 #6

P: n/a
ads
Hmmm...can u please elaborate your statement? I do receive the error message
"Cannot have multiple items selected in a dropdownlist." Why cant i use the
code for dropdownlist if its provided there?

"Karl Seguin [MVP]" wrote:
well that clears that up. I didn't think you were setting multiple values.
You can't do that in a dropdownbox, use a listbox instead.

Karl

--
http://www.openmymind.net/

"ads" <ad*@discussions.microsoft.com> wrote in message
news:D0**********************************@microsof t.com...
yes.the separate function is called when !ispostback too. Heres the
complete
code:

if (!IsPostBack)
{
if (Request.QueryString["id"]!= null)
{
BindDDL();

LoadSelectedAffiliation(int.Parse(Request.QueryStr ing["id"].ToString()));
}

}

private void LoadSelectedAffiliation(int id)
{
SqlDataReader dr =
Microsoft.ApplicationBlocks.Data.SqlHelper.Execute Reader(System.Configuration.ConfigurationSettings. AppSettings["connectionstring"],
CommandType.Text, "select * from jbaffiliates where affiliateid=" + id);
ddlYrJoined.ClearSelection();
ddlYrLeft.ClearSelection();
while (dr.Read())
{
orgname.Text = dr["orgname"].ToString();
orgloc.Text = dr["orglocation"].ToString();

ddlYrJoined.Items.FindByValue(dr["yrstart"].ToString()).Selected
= true;
ddlYrLeft.Items.FindByValue(dr["yrend"].ToString()).Selected =
true;
position.Text = dr["highestpositiontitle"].ToString();
responsibilities.Text = dr["responsibilities"].ToString();
}
dr.Close();
}

private void BindDDL()
{
for (int i = DateTime.Now.Year; i > DateTime.Now.Year - 50; i--)
{
ListItem li = new ListItem(i.ToString(), i.ToString());
ddlYrJoined.Items.Add(li);
ddlYrLeft.Items.Add(li);

}
ddlYrLeft.Items.Insert(0, "SELECT");
ddlYrJoined.Items.Insert(0,"SELECT");
}
"Karl Seguin [MVP]" wrote:
Is the separate function also called when !ispostback? You had also
mentioned ClearSelection() but I don't see that anywhere..

KArl

--
http://www.openmymind.net/

"ads" <ad*@discussions.microsoft.com> wrote in message
news:3C**********************************@microsof t.com...
> //build the datasource of the 2 dropdownlists on page load
>
> if(!ispostback)
> {
> for (int i = DateTime.Now.Year; i > DateTime.Now.Year - 50; i--)
> {
> ListItem li = new ListItem(i.ToString(), i.ToString());
> ddlYrJoined.Items.Add(li);
> ddlYrLeft.Items.Add(li);
>
> }
> ddlYrLeft.Items.Insert(0, "SELECT");
> ddlYrJoined.Items.Insert(0,"SELECT");
> }
>
> //on a separate function
>
> ddlYrJoined.Items.FindByValue(dr["yrstart"].ToString()).Selected =
> true;
>
> //where dr["yrstart"].ToString() is a datareader getting its values
> from a
> database
>
> "Karl Seguin [MVP]" wrote:
>
>> Can we see your complete code? I'm not familiar with ClearSelection
>> (don't
>> see it in the docs right now for some reason??)
>>
>> Karl
>> --
>> http://www.openmymind.net/
>>
>>
>>
>> "ads" <ad*@discussions.microsoft.com> wrote in message
>> news:BC**********************************@microsof t.com...
>> > 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
>>
>>
>>


Feb 16 '06 #7

P: n/a
Well, you are trying to have multiple values selected. The DropDownList
simply doesn't allow this to happen. To be able to have multiple values
selected, you need to use a ListBox instead of a DropDownBox.

Karl

--
http://www.openmymind.net/

"ads" <ad*@discussions.microsoft.com> wrote in message
news:48**********************************@microsof t.com...
Hmmm...can u please elaborate your statement? I do receive the error
message
"Cannot have multiple items selected in a dropdownlist." Why cant i use
the
code for dropdownlist if its provided there?

"Karl Seguin [MVP]" wrote:
well that clears that up. I didn't think you were setting multiple
values.
You can't do that in a dropdownbox, use a listbox instead.

Karl

--
http://www.openmymind.net/

"ads" <ad*@discussions.microsoft.com> wrote in message
news:D0**********************************@microsof t.com...
> yes.the separate function is called when !ispostback too. Heres the
> complete
> code:
>
> if (!IsPostBack)
> {
> if (Request.QueryString["id"]!= null)
> {
> BindDDL();
>
> LoadSelectedAffiliation(int.Parse(Request.QueryStr ing["id"].ToString()));
> }
>
> }
>
> private void LoadSelectedAffiliation(int id)
> {
> SqlDataReader dr =
> Microsoft.ApplicationBlocks.Data.SqlHelper.Execute Reader(System.Configuration.ConfigurationSettings. AppSettings["connectionstring"],
> CommandType.Text, "select * from jbaffiliates where affiliateid=" +
> id);
> ddlYrJoined.ClearSelection();
> ddlYrLeft.ClearSelection();
> while (dr.Read())
> {
> orgname.Text = dr["orgname"].ToString();
> orgloc.Text = dr["orglocation"].ToString();
>
> ddlYrJoined.Items.FindByValue(dr["yrstart"].ToString()).Selected
> = true;
> ddlYrLeft.Items.FindByValue(dr["yrend"].ToString()).Selected
> =
> true;
> position.Text = dr["highestpositiontitle"].ToString();
> responsibilities.Text = dr["responsibilities"].ToString();
> }
> dr.Close();
> }
>
> private void BindDDL()
> {
> for (int i = DateTime.Now.Year; i > DateTime.Now.Year - 50; i--)
> {
> ListItem li = new ListItem(i.ToString(), i.ToString());
> ddlYrJoined.Items.Add(li);
> ddlYrLeft.Items.Add(li);
>
> }
> ddlYrLeft.Items.Insert(0, "SELECT");
> ddlYrJoined.Items.Insert(0,"SELECT");
> }
>
>
> "Karl Seguin [MVP]" wrote:
>
>> Is the separate function also called when !ispostback? You had also
>> mentioned ClearSelection() but I don't see that anywhere..
>>
>> KArl
>>
>> --
>> http://www.openmymind.net/
>>
>>
>>
>> "ads" <ad*@discussions.microsoft.com> wrote in message
>> news:3C**********************************@microsof t.com...
>> > //build the datasource of the 2 dropdownlists on page load
>> >
>> > if(!ispostback)
>> > {
>> > for (int i = DateTime.Now.Year; i > DateTime.Now.Year - 50; i--)
>> > {
>> > ListItem li = new ListItem(i.ToString(), i.ToString());
>> > ddlYrJoined.Items.Add(li);
>> > ddlYrLeft.Items.Add(li);
>> >
>> > }
>> > ddlYrLeft.Items.Insert(0, "SELECT");
>> > ddlYrJoined.Items.Insert(0,"SELECT");
>> > }
>> >
>> > //on a separate function
>> >
>> > ddlYrJoined.Items.FindByValue(dr["yrstart"].ToString()).Selected =
>> > true;
>> >
>> > //where dr["yrstart"].ToString() is a datareader getting its values
>> > from a
>> > database
>> >
>> > "Karl Seguin [MVP]" wrote:
>> >
>> >> Can we see your complete code? I'm not familiar with ClearSelection
>> >> (don't
>> >> see it in the docs right now for some reason??)
>> >>
>> >> Karl
>> >> --
>> >> http://www.openmymind.net/
>> >>
>> >>
>> >>
>> >> "ads" <ad*@discussions.microsoft.com> wrote in message
>> >> news:BC**********************************@microsof t.com...
>> >> > 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
>> >>
>> >>
>> >>
>>
>>
>>


Feb 16 '06 #8

P: n/a
ads
In the first function BindDDL() im just binding the datasource to the
dropdownlists and in the second function,im trying to select an item for each
dropdownlist. Please take note that there are 2 dropdownlist in my code
(ddlYrJoined and ddlYrLeft). Im a bit confuse. I know its not allowed to have
multiple selection in a dropdownlist. Which part of the code am i trying to
select multiple values?

"Karl Seguin [MVP]" wrote:
Well, you are trying to have multiple values selected. The DropDownList
simply doesn't allow this to happen. To be able to have multiple values
selected, you need to use a ListBox instead of a DropDownBox.

Karl

--
http://www.openmymind.net/

"ads" <ad*@discussions.microsoft.com> wrote in message
news:48**********************************@microsof t.com...
Hmmm...can u please elaborate your statement? I do receive the error
message
"Cannot have multiple items selected in a dropdownlist." Why cant i use
the
code for dropdownlist if its provided there?

"Karl Seguin [MVP]" wrote:
well that clears that up. I didn't think you were setting multiple
values.
You can't do that in a dropdownbox, use a listbox instead.

Karl

--
http://www.openmymind.net/

"ads" <ad*@discussions.microsoft.com> wrote in message
news:D0**********************************@microsof t.com...
> yes.the separate function is called when !ispostback too. Heres the
> complete
> code:
>
> if (!IsPostBack)
> {
> if (Request.QueryString["id"]!= null)
> {
> BindDDL();
>
> LoadSelectedAffiliation(int.Parse(Request.QueryStr ing["id"].ToString()));
> }
>
> }
>
> private void LoadSelectedAffiliation(int id)
> {
> SqlDataReader dr =
> Microsoft.ApplicationBlocks.Data.SqlHelper.Execute Reader(System.Configuration.ConfigurationSettings. AppSettings["connectionstring"],
> CommandType.Text, "select * from jbaffiliates where affiliateid=" +
> id);
> ddlYrJoined.ClearSelection();
> ddlYrLeft.ClearSelection();
> while (dr.Read())
> {
> orgname.Text = dr["orgname"].ToString();
> orgloc.Text = dr["orglocation"].ToString();
>
> ddlYrJoined.Items.FindByValue(dr["yrstart"].ToString()).Selected
> = true;
> ddlYrLeft.Items.FindByValue(dr["yrend"].ToString()).Selected
> =
> true;
> position.Text = dr["highestpositiontitle"].ToString();
> responsibilities.Text = dr["responsibilities"].ToString();
> }
> dr.Close();
> }
>
> private void BindDDL()
> {
> for (int i = DateTime.Now.Year; i > DateTime.Now.Year - 50; i--)
> {
> ListItem li = new ListItem(i.ToString(), i.ToString());
> ddlYrJoined.Items.Add(li);
> ddlYrLeft.Items.Add(li);
>
> }
> ddlYrLeft.Items.Insert(0, "SELECT");
> ddlYrJoined.Items.Insert(0,"SELECT");
> }
>
>
> "Karl Seguin [MVP]" wrote:
>
>> Is the separate function also called when !ispostback? You had also
>> mentioned ClearSelection() but I don't see that anywhere..
>>
>> KArl
>>
>> --
>> http://www.openmymind.net/
>>
>>
>>
>> "ads" <ad*@discussions.microsoft.com> wrote in message
>> news:3C**********************************@microsof t.com...
>> > //build the datasource of the 2 dropdownlists on page load
>> >
>> > if(!ispostback)
>> > {
>> > for (int i = DateTime.Now.Year; i > DateTime.Now.Year - 50; i--)
>> > {
>> > ListItem li = new ListItem(i.ToString(), i.ToString());
>> > ddlYrJoined.Items.Add(li);
>> > ddlYrLeft.Items.Add(li);
>> >
>> > }
>> > ddlYrLeft.Items.Insert(0, "SELECT");
>> > ddlYrJoined.Items.Insert(0,"SELECT");
>> > }
>> >
>> > //on a separate function
>> >
>> > ddlYrJoined.Items.FindByValue(dr["yrstart"].ToString()).Selected =
>> > true;
>> >
>> > //where dr["yrstart"].ToString() is a datareader getting its values
>> > from a
>> > database
>> >
>> > "Karl Seguin [MVP]" wrote:
>> >
>> >> Can we see your complete code? I'm not familiar with ClearSelection
>> >> (don't
>> >> see it in the docs right now for some reason??)
>> >>
>> >> Karl
>> >> --
>> >> http://www.openmymind.net/
>> >>
>> >>
>> >>
>> >> "ads" <ad*@discussions.microsoft.com> wrote in message
>> >> news:BC**********************************@microsof t.com...
>> >> > 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
>> >>
>> >>
>> >>
>>
>>
>>


Feb 17 '06 #9

P: n/a
while (dr.Read())
{
orgname.Text = dr["orgname"].ToString();
orgloc.Text = dr["orglocation"].ToString();
ddlYrJoined.Items.FindByValue(dr["yrstart"].ToString()).Selected = true;
ddlYrLeft.Items.FindByValue(dr["yrend"].ToString()).Selected = true;
position.Text = dr["highestpositiontitle"].ToString();
responsibilities.Text = dr["responsibilities"].ToString();
}

if your data reader contains more than 1 record, u'll be looping through it
and trying to assign a different dr["ystart"] and dr["yrend"] to each
dropdown

Karl
--
http://www.openmymind.net/

"ads" <ad*@discussions.microsoft.com> wrote in message
news:A1**********************************@microsof t.com...
In the first function BindDDL() im just binding the datasource to the
dropdownlists and in the second function,im trying to select an item for
each
dropdownlist. Please take note that there are 2 dropdownlist in my code
(ddlYrJoined and ddlYrLeft). Im a bit confuse. I know its not allowed to
have
multiple selection in a dropdownlist. Which part of the code am i trying
to
select multiple values?

"Karl Seguin [MVP]" wrote:
Well, you are trying to have multiple values selected. The DropDownList
simply doesn't allow this to happen. To be able to have multiple values
selected, you need to use a ListBox instead of a DropDownBox.

Karl

--
http://www.openmymind.net/

"ads" <ad*@discussions.microsoft.com> wrote in message
news:48**********************************@microsof t.com...
> Hmmm...can u please elaborate your statement? I do receive the error
> message
> "Cannot have multiple items selected in a dropdownlist." Why cant i use
> the
> code for dropdownlist if its provided there?
>
> "Karl Seguin [MVP]" wrote:
>
>> well that clears that up. I didn't think you were setting multiple
>> values.
>> You can't do that in a dropdownbox, use a listbox instead.
>>
>> Karl
>>
>> --
>> http://www.openmymind.net/
>>
>>
>>
>> "ads" <ad*@discussions.microsoft.com> wrote in message
>> news:D0**********************************@microsof t.com...
>> > yes.the separate function is called when !ispostback too. Heres the
>> > complete
>> > code:
>> >
>> > if (!IsPostBack)
>> > {
>> > if (Request.QueryString["id"]!= null)
>> > {
>> > BindDDL();
>> >
>> > LoadSelectedAffiliation(int.Parse(Request.QueryStr ing["id"].ToString()));
>> > }
>> >
>> > }
>> >
>> > private void LoadSelectedAffiliation(int id)
>> > {
>> > SqlDataReader dr =
>> > Microsoft.ApplicationBlocks.Data.SqlHelper.Execute Reader(System.Configuration.ConfigurationSettings. AppSettings["connectionstring"],
>> > CommandType.Text, "select * from jbaffiliates where affiliateid=" +
>> > id);
>> > ddlYrJoined.ClearSelection();
>> > ddlYrLeft.ClearSelection();
>> > while (dr.Read())
>> > {
>> > orgname.Text = dr["orgname"].ToString();
>> > orgloc.Text = dr["orglocation"].ToString();
>> >
>> > ddlYrJoined.Items.FindByValue(dr["yrstart"].ToString()).Selected
>> > = true;
>> >
>> > ddlYrLeft.Items.FindByValue(dr["yrend"].ToString()).Selected
>> > =
>> > true;
>> > position.Text = dr["highestpositiontitle"].ToString();
>> > responsibilities.Text =
>> > dr["responsibilities"].ToString();
>> > }
>> > dr.Close();
>> > }
>> >
>> > private void BindDDL()
>> > {
>> > for (int i = DateTime.Now.Year; i > DateTime.Now.Year - 50;
>> > i--)
>> > {
>> > ListItem li = new ListItem(i.ToString(), i.ToString());
>> > ddlYrJoined.Items.Add(li);
>> > ddlYrLeft.Items.Add(li);
>> >
>> > }
>> > ddlYrLeft.Items.Insert(0, "SELECT");
>> > ddlYrJoined.Items.Insert(0,"SELECT");
>> > }
>> >
>> >
>> > "Karl Seguin [MVP]" wrote:
>> >
>> >> Is the separate function also called when !ispostback? You had also
>> >> mentioned ClearSelection() but I don't see that anywhere..
>> >>
>> >> KArl
>> >>
>> >> --
>> >> http://www.openmymind.net/
>> >>
>> >>
>> >>
>> >> "ads" <ad*@discussions.microsoft.com> wrote in message
>> >> news:3C**********************************@microsof t.com...
>> >> > //build the datasource of the 2 dropdownlists on page load
>> >> >
>> >> > if(!ispostback)
>> >> > {
>> >> > for (int i = DateTime.Now.Year; i > DateTime.Now.Year - 50; i--)
>> >> > {
>> >> > ListItem li = new ListItem(i.ToString(),
>> >> > i.ToString());
>> >> > ddlYrJoined.Items.Add(li);
>> >> > ddlYrLeft.Items.Add(li);
>> >> >
>> >> > }
>> >> > ddlYrLeft.Items.Insert(0, "SELECT");
>> >> > ddlYrJoined.Items.Insert(0,"SELECT");
>> >> > }
>> >> >
>> >> > //on a separate function
>> >> >
>> >> > ddlYrJoined.Items.FindByValue(dr["yrstart"].ToString()).Selected
>> >> > =
>> >> > true;
>> >> >
>> >> > //where dr["yrstart"].ToString() is a datareader getting its
>> >> > values
>> >> > from a
>> >> > database
>> >> >
>> >> > "Karl Seguin [MVP]" wrote:
>> >> >
>> >> >> Can we see your complete code? I'm not familiar with
>> >> >> ClearSelection
>> >> >> (don't
>> >> >> see it in the docs right now for some reason??)
>> >> >>
>> >> >> Karl
>> >> >> --
>> >> >> http://www.openmymind.net/
>> >> >>
>> >> >>
>> >> >>
>> >> >> "ads" <ad*@discussions.microsoft.com> wrote in message
>> >> >> news:BC**********************************@microsof t.com...
>> >> >> > 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
>> >> >>
>> >> >>
>> >> >>
>> >>
>> >>
>> >>
>>
>>
>>


Feb 17 '06 #10

P: n/a
ads
Though im assuming there's only 1 record, i'll check if theres more record.
Better if i remove the while loop.
Thanks Karl

"Karl Seguin [MVP]" wrote:
while (dr.Read())
{
orgname.Text = dr["orgname"].ToString();
orgloc.Text = dr["orglocation"].ToString();
ddlYrJoined.Items.FindByValue(dr["yrstart"].ToString()).Selected = true;
ddlYrLeft.Items.FindByValue(dr["yrend"].ToString()).Selected = true;
position.Text = dr["highestpositiontitle"].ToString();
responsibilities.Text = dr["responsibilities"].ToString();
}

if your data reader contains more than 1 record, u'll be looping through it
and trying to assign a different dr["ystart"] and dr["yrend"] to each
dropdown

Karl
--
http://www.openmymind.net/

"ads" <ad*@discussions.microsoft.com> wrote in message
news:A1**********************************@microsof t.com...
In the first function BindDDL() im just binding the datasource to the
dropdownlists and in the second function,im trying to select an item for
each
dropdownlist. Please take note that there are 2 dropdownlist in my code
(ddlYrJoined and ddlYrLeft). Im a bit confuse. I know its not allowed to
have
multiple selection in a dropdownlist. Which part of the code am i trying
to
select multiple values?

"Karl Seguin [MVP]" wrote:
Well, you are trying to have multiple values selected. The DropDownList
simply doesn't allow this to happen. To be able to have multiple values
selected, you need to use a ListBox instead of a DropDownBox.

Karl

--
http://www.openmymind.net/

"ads" <ad*@discussions.microsoft.com> wrote in message
news:48**********************************@microsof t.com...
> Hmmm...can u please elaborate your statement? I do receive the error
> message
> "Cannot have multiple items selected in a dropdownlist." Why cant i use
> the
> code for dropdownlist if its provided there?
>
> "Karl Seguin [MVP]" wrote:
>
>> well that clears that up. I didn't think you were setting multiple
>> values.
>> You can't do that in a dropdownbox, use a listbox instead.
>>
>> Karl
>>
>> --
>> http://www.openmymind.net/
>>
>>
>>
>> "ads" <ad*@discussions.microsoft.com> wrote in message
>> news:D0**********************************@microsof t.com...
>> > yes.the separate function is called when !ispostback too. Heres the
>> > complete
>> > code:
>> >
>> > if (!IsPostBack)
>> > {
>> > if (Request.QueryString["id"]!= null)
>> > {
>> > BindDDL();
>> >
>> > LoadSelectedAffiliation(int.Parse(Request.QueryStr ing["id"].ToString()));
>> > }
>> >
>> > }
>> >
>> > private void LoadSelectedAffiliation(int id)
>> > {
>> > SqlDataReader dr =
>> > Microsoft.ApplicationBlocks.Data.SqlHelper.Execute Reader(System.Configuration.ConfigurationSettings. AppSettings["connectionstring"],
>> > CommandType.Text, "select * from jbaffiliates where affiliateid=" +
>> > id);
>> > ddlYrJoined.ClearSelection();
>> > ddlYrLeft.ClearSelection();
>> > while (dr.Read())
>> > {
>> > orgname.Text = dr["orgname"].ToString();
>> > orgloc.Text = dr["orglocation"].ToString();
>> >
>> > ddlYrJoined.Items.FindByValue(dr["yrstart"].ToString()).Selected
>> > = true;
>> >
>> > ddlYrLeft.Items.FindByValue(dr["yrend"].ToString()).Selected
>> > =
>> > true;
>> > position.Text = dr["highestpositiontitle"].ToString();
>> > responsibilities.Text =
>> > dr["responsibilities"].ToString();
>> > }
>> > dr.Close();
>> > }
>> >
>> > private void BindDDL()
>> > {
>> > for (int i = DateTime.Now.Year; i > DateTime.Now.Year - 50;
>> > i--)
>> > {
>> > ListItem li = new ListItem(i.ToString(), i.ToString());
>> > ddlYrJoined.Items.Add(li);
>> > ddlYrLeft.Items.Add(li);
>> >
>> > }
>> > ddlYrLeft.Items.Insert(0, "SELECT");
>> > ddlYrJoined.Items.Insert(0,"SELECT");
>> > }
>> >
>> >
>> > "Karl Seguin [MVP]" wrote:
>> >
>> >> Is the separate function also called when !ispostback? You had also
>> >> mentioned ClearSelection() but I don't see that anywhere..
>> >>
>> >> KArl
>> >>
>> >> --
>> >> http://www.openmymind.net/
>> >>
>> >>
>> >>
>> >> "ads" <ad*@discussions.microsoft.com> wrote in message
>> >> news:3C**********************************@microsof t.com...
>> >> > //build the datasource of the 2 dropdownlists on page load
>> >> >
>> >> > if(!ispostback)
>> >> > {
>> >> > for (int i = DateTime.Now.Year; i > DateTime.Now.Year - 50; i--)
>> >> > {
>> >> > ListItem li = new ListItem(i.ToString(),
>> >> > i.ToString());
>> >> > ddlYrJoined.Items.Add(li);
>> >> > ddlYrLeft.Items.Add(li);
>> >> >
>> >> > }
>> >> > ddlYrLeft.Items.Insert(0, "SELECT");
>> >> > ddlYrJoined.Items.Insert(0,"SELECT");
>> >> > }
>> >> >
>> >> > //on a separate function
>> >> >
>> >> > ddlYrJoined.Items.FindByValue(dr["yrstart"].ToString()).Selected
>> >> > =
>> >> > true;
>> >> >
>> >> > //where dr["yrstart"].ToString() is a datareader getting its
>> >> > values
>> >> > from a
>> >> > database
>> >> >
>> >> > "Karl Seguin [MVP]" wrote:
>> >> >
>> >> >> Can we see your complete code? I'm not familiar with
>> >> >> ClearSelection
>> >> >> (don't
>> >> >> see it in the docs right now for some reason??)
>> >> >>
>> >> >> Karl
>> >> >> --
>> >> >> http://www.openmymind.net/
>> >> >>
>> >> >>
>> >> >>
>> >> >> "ads" <ad*@discussions.microsoft.com> wrote in message
>> >> >> news:BC**********************************@microsof t.com...
>> >> >> > 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
>> >> >>
>> >> >>
>> >> >>
>> >>
>> >>
>> >>
>>
>>
>>


Feb 28 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.