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

dropdownlist multiple selection problem

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
10 6329
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
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Brennon Arnold | last post by:
I have a problem that I figured would be relatively common, but have been unable to find any information on it as of yet. I have a page that contains two DropDownList controls, with the second...
4
by: theo | last post by:
Program flow...load file,then extract the xml text tags from the file,then the number of Xml tags retrieved from the file determines the number of dropdownlist controls instanciated in the...
3
by: Tim::.. | last post by:
Can someone please tell me how I go about preselecting an item in a drop drown list when I click the Edit Command in a datagrid? I have tried the following but it doesn't work for me! I would...
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 =...
1
by: Michael Groeger | last post by:
Hi, I want to be able to have a DropDownList which supports multiple selection, but I haven't found a property for that in the DropDownList control. Is there a way to have multiple selection...
2
by: Steffen Loringer | last post by:
Hi all, may be an easy question: How can I allow multiple selections in a dropdownlist? Thanks Steffen
0
by: Tand35006 | last post by:
Hi, I hope some one can help with this. I have a basic webform with 2 DropDownLists and a single DataGrid. What I am trying to do is populate the first DDList from a dataset on Form_Load. I then...
1
by: Trevor Bezotte | last post by:
Hi, I'm new to asp.net. I am having trouble updating and displaying a profile property through a dropdownlist. I believe the problem has something to do with autoeventwireup but I'm not sure. If...
11
by: Santosh | last post by:
Dear all , i am writting following code. if(Page.IsPostBack==false) { try { BindSectionDropDownlist();
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.