Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Removing items from A dropdown List Please help
Hi,


This is concerned with System.Web.UI.WebControls.Drop=ADDownList


I am having problems creating a method which will remove list items
from a preloaded dropdownlist. This dropdown is loaded when the page
loads and the items are pulled from a database.


I want to create a method which is called on the page load and will
remove certain items from the dropdown list. I want the method to loop
through each list item and remove it if its value =3D "Not Given"


The reason i am dong this is because i have to load all the items in
first and then use a different method to remove the undesired ones. I
do not want the user to be able to select or even see the "Not Given"
Option


My dropdown list is called ddlOccupationStatus
My method is called        ClipDropDowns();


I cannot get the correct logic in place to loop through the list and
the remove the undesired items, can anyone help?


Any answers or help will be greatly appreciated....


I have tried the follwing methods but to no avail:


private void ClipDropDowns()
{
if (ddlOccupationStatus.SelectedV=ADalue.Equals("Not Asked"))
{
ddlOccupationStatus.SelectedVa=ADlue.Remove("Not Asked);
}



}


I have also tried:

private void ClipDropDowns()
{
for(int i=3D0; i < 20; i++)
{
if (ddlOccupationStatus.Items(i) =3D=3D "Not Asked")
{
ddlOccupationStatus.Items.Remo=ADve(i,1);=20
}=20


}
}


Report this thread to moderator Post Follow-up to this message
Old Post
frawls@gmail.com
05-09-05 08:59 PM


Re: Removing items from A dropdown List Please help
Hi,

Just try this out :
private void RemoveValue()
{
for(int i=0; i<drpList.Items.Count; i++)
{
if(drpList.Items[i].Value == "true")
{
drpList.Items.RemoveAt(i);
// Here i is decremented because when you remove
the value from the
// the list the length is automatically decreased by
one. So the next item
// will be a index i and if we increment it we skip
one value.
i--;
}
}
}


HTH,
Regards,
Angrez


Report this thread to moderator Post Follow-up to this message
Old Post
Angrez Singh
05-09-05 08:59 PM


Re: Removing items from A dropdown List Please help
Hi Angrez

Thank you for you reply, thats great. The solution you gave me worked
perfectly!! Thank you so much, i really appreciate your help, i will be
implementing your solution all around my application....

Frawls


Report this thread to moderator Post Follow-up to this message
Old Post
Frawls
05-10-05 01:57 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

C# archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 09:53 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.