Solved

Compare listbox with array and then listout the item not present in the listbox

Posted on 2004-10-13
6
314 Views
Last Modified: 2010-04-17
Hi All
 I Want To Achieve This In Asp.Net
"   Compare listbox with an array and then listout the item not present in the listbox  "
Can Anyone Plz Help Me
Advance Thanx
Nalinkumarbalaji
0
Comment
Question by:Nalinkumarbalaji
  • 2
  • 2
6 Comments
 
LVL 19

Accepted Solution

by:
arif_eqbal earned 63 total points
ID: 12296939
I think You'll have to go Through a Loop

For each Item in the List box call a Function that compares it with items in Array

0
 
LVL 11

Assisted Solution

by:pratap_r
pratap_r earned 62 total points
ID: 12297328
assuming this is in the listbox
<asp:ListBox id="ListBox1" runat="server">
      <asp:ListItem>Item 1</asp:ListItem>
      <asp:ListItem>Item 2</asp:ListItem>
      <asp:ListItem>Item 3</asp:ListItem>
      <asp:ListItem>Item 4</asp:ListItem>
</asp:ListBox>

your c# code will probably be (i am putting it in page load)

string []st=new string[]{"Item 1","Item 10","Item 9"};

foreach(string s in st)
{
      if(ListBox1.Items.FindByText(s)==null)
            Response.Write("Item : " +  s + " Not Found <br>");
}

Got it?

Enjoy!
Pratap
0
 
LVL 19

Expert Comment

by:arif_eqbal
ID: 12305120
Well a better method will be Loop for all Items in the ListBox and user Array.BinarySearch in the Array.

It'll be Faster.

0
 
LVL 11

Expert Comment

by:pratap_r
ID: 12305573
well it depends on which one has more items.. :-) its always debatable.

Pratap
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show, step by step, how to integrate R code into a R Sweave document
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now