Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 342
  • Last Modified:

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

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
Nalinkumarbalaji
Asked:
Nalinkumarbalaji
  • 2
  • 2
2 Solutions
 
arif_eqbalCommented:
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
 
pratap_rCommented:
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
 
arif_eqbalCommented:
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
 
pratap_rCommented:
well it depends on which one has more items.. :-) its always debatable.

Pratap
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now