473,385 Members | 1,523 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,385 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 6338
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();
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.