dropdownlist multiple selection problem

G

Guest

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
 
K

Karl Seguin [MVP]

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
 
G

Guest

//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
 
K

Karl Seguin [MVP]

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 said:
//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 said:
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
 
G

Guest

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");
}


Karl Seguin said:
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 said:
//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 said:
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
 
K

Karl Seguin [MVP]

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 said:
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");
}


Karl Seguin said:
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 said:
//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
 
G

Guest

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 said:
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 said:
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");
}


Karl Seguin said:
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
 
K

Karl Seguin [MVP]

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 said:
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 said:
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 said:
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
 
G

Guest

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 said:
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 said:
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 said:
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
 
K

Karl Seguin [MVP]

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 said:
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 said:
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 said:
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
 
G

Guest

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 said:
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 said:
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 said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top