dotnetspider.com
Login Login    Register      

TutorialsForumCareer DevelopmentResourcesReviewsJobsInterviewCommunitiesProjectsTraining

Subscribe to Subscribers
Talk to Webmaster
Tony John

Facebook
Google+
Twitter
LinkedIn
Online MembersMore...
Join our online Google+ community for Bloggers, Content Writers and Webmasters




Forums » .NET » ASP.NET »

How to Remove List ITems


Posted Date: 15 Apr 2012      Posted By:: R.Jaya kumar (JK)     Member Level: Gold    Member Rank: 70     Points: 1   Responses: 3



Hi

i have list items 10
here how to remove my listitems after 5 how will do this


Thanks and Regards
Name : Jayakumar
Email Id :kumaraspcode2009@gmail.com

Do not forget to Rate the post...
Check This url




Responses

#666496    Author: Ajatshatru Upadhyay      Member Level: Gold      Member Rank: 20     Date: 16/Apr/2012   Rating: 2 out of 52 out of 5     Points: 2

Hi,
Here you go:


// removing by value
ListItem itemToRemove = DDL.Items.FindByValue("value");
if (itemToRemove != null)
{
DDL.Remove(itemToRemove);
}
// removing by index number
DDL.Items.RemoveAt(index_number);


Or even through a loop:


int count = DDL.Items.Count - 1;

for (int i = count; i > 0; i--)
{
if(i > 5)
{
DDL.Items.RemoveAt(i);
}
}


Hope it'll help you.
Regards
Ajatshatru



 
#666502    Author: Anil Kumar Pandey      Member Level: Platinum      Member Rank: 1     Date: 16/Apr/2012   Rating: 2 out of 52 out of 5     Points: 2

you can use a loop for removing items as


for(int i=5;i<lstItem.Count;i++)
{
lstItem.RemoveAt(i);
}


Thanks & Regards
Anil Kumar Pandey
Microsoft MVP, DNS MVM



 
#666505    Author: Bijit      Member Level: Gold      Member Rank: 157     Date: 16/Apr/2012   Rating: 2 out of 52 out of 5     Points: 2

Try this code



List<int> list = new List<int>();

foreach (int i in list)
{
list.Remove(i);
}








 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Next : Insert,update,delete gridview in ASP.NET C# .net
Previous : How to count dynamically created radio button list control list item clicks
Return to Discussion Forum
Post New Message
Category:

Related Messages



Follow us on Twitter: https://twitter.com/dotnetspider

Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds


    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.