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/
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?
:
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/
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.QueryString["id"].ToString()));
}
}
private void LoadSelectedAffiliation(int id)
{
SqlDataReader dr =
Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteReader(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");
}
:
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/
//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
:
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/
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