Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Professionals
|
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Professionals section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 22nd, 2010, 10:45 PM
Authorized User
 
Join Date: Mar 2009
Posts: 74
Thanks: 5
Thanked 0 Times in 0 Posts
Default Having Trouble with dropdownlist boxes on dynamically loaded user control

Hello all,
I have for two days now been trying to debug what appears to be a serious logical error in my code, now I think I need to make it public. I am working on a dynamically loaded user control, this usercontrol has two dropdownlists, followed by textboxes.The second dropdownlist is populated based on the selectedindex of the first dropdwonlist.
What I do is that, when the selectedindex of the first dropdownlist changes, I clear the items in the second list, then populate it.based on the selected index of dropdownlistbox.
Now the textboxes are all set to visibility=false. This is because the textboxes to show will depend on the selected index of the second dropdownlist box. The problem is that each time I select an item from the second drop downlistbox, the selected index of the second drop that listbox (this determines the textboxes to reveal) shows -1, instead of the actual selected index of the dropdownlist box, which I expect to be 0, 1,2 etc. and this courses the selected index of the second listbox to always reset back to the first item, causing the textboxes to be revealed wrongly. Idont know if am clear enuff?
Both listboxes are in ajax update panels.

Here a portion of my code if u would like to see:
//This is the first listbox that Loads the second listbox

protected void ListBoxProjects_SelectedIndexChanged(object sender, EventArgs e)
{
//Clear second listbox
ListBoxSources.Items.Clear();
//populate second listbox
LoadControlByProject();

}

//This is the method that loads the second list box, called in selectedIndexChanged above
protected void LoadControlByProject()
{
//Clear second listbox
//ListBoxSources.Items.Clear();

//Call method that returns linq query result for second dropdownlist box
foreach (var i in ControlLoader.GetSource(lstProjectsId.ElementAt(Li stBoxProjects.SelectedIndex)))
{
// ddlSource.Items.Add(i.SourceName);
ListBoxSources.Items.Add(i.SourceName);

}
}

//This is the selectedIndex_changed of the second list box

protected void ListBoxSources_SelectedIndexChanged(object sender, EventArgs e)
{

//This sets a static int that will hold the selected index
lstSelectIndex = ListBoxSources.SelectedIndex;

//This sets the visibility of my textboxes
ToggleControls();
//Clear ListBoxSources
ListBoxSources.Items.Clear();
//This is meant to populate the second listbox again, paasing the
//The selected index as a parameter, so that the selected item
// remains selected (custom method)
LoadControlByProject(lstSelectIndex);

}

Any hint appreciated, thanks

Last edited by ysfkay; June 22nd, 2010 at 10:47 PM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
dynamically loaded scripts chameleon Javascript 2 January 14th, 2010 08:58 AM
Problem with dynamically loaded user control CodeBest ASP.NET 2.0 Basics 0 February 7th, 2009 09:42 AM
Loading user control dynamically from code-behind jacob ASP.NET 1.0 and 1.1 Basics 2 April 12th, 2004 06:06 PM
Programmatically Loaded User Control Event Handlin cgoldrin ASP.NET 1.0 and 1.1 Professional 4 December 2nd, 2003 09:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.