
Signature
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..
[quoted text clipped - 41 lines]
> >> >
> >> > Ads
Karl Seguin [MVP] - 15 Feb 2006 12:22 GMT
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

Signature
http://www.openmymind.net/
> yes.the separate function is called when !ispostback too. Heres the
> complete
[quoted text clipped - 96 lines]
>> >> >
>> >> > Ads
ads - 16 Feb 2006 03:14 GMT
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.
[quoted text clipped - 101 lines]
> >> >> >
> >> >> > Ads
Karl Seguin [MVP] - 16 Feb 2006 11:51 GMT
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

Signature
http://www.openmymind.net/
> Hmmm...can u please elaborate your statement? I do receive the error
> message
[quoted text clipped - 113 lines]
>> >> >> >
>> >> >> > Ads
ads - 17 Feb 2006 02:01 GMT
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?
> 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
[quoted text clipped - 119 lines]
> >> >> >> >
> >> >> >> > Ads
Karl Seguin [MVP] - 17 Feb 2006 12:05 GMT
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

Signature
http://www.openmymind.net/
> 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
[quoted text clipped - 137 lines]
>> >> >> >> >
>> >> >> >> > Ads
ads - 28 Feb 2006 01:19 GMT
Though im assuming there's only 1 record, i'll check if theres more record.
Better if i remove the while loop.
Thanks Karl
> while (dr.Read())
> {
[quoted text clipped - 152 lines]
> >> >> >> >> >
> >> >> >> >> > Ads