DROPDOWNLIST databound and unbound

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • femina
    New Member
    • Dec 2007
    • 35

    DROPDOWNLIST databound and unbound

    i have a confusion
    please help me with the reason
    in my ASP.NET web page i have two drop down list
    DropDownLis1 is unbound and DropDownList2 is data bound to my table named Employee

    Code:
    //unbound (items are Apples,Oranges,Grapes,Fruits)
    string s="",str="";
    foreach (ListItem li in DropDownList1.Items) 
            {
               bool b = li.Text.Equals("Apples");   //true for Apples
                str += b;  //true for Apples
                if (b) //li.Text.Equals("Apples"))
                {
                  s += " the Selection is " + li.Text+" ";
                }
                s += li.Text;
            }
            Label1.Text = s +" str "+str;
    Code:
    //bound ( Employee table has employee names //Femina,ramya,jyothi,Nilafer,Fayaz)
    string ss = "";
           foreach (ListItem li in DropDownList2.Items)
           {
            bool b = li.Text.Equals("Femina"); //here its never true but dont know why
                
                if (li.Text.Equals("Femina")) //not executed at all 
                {
                    ss += " selection is " + li.Text +" ";
                }
                ss += li.Text;
            }
            Label4.Text += ss;
    so in these two DDLs DropDownList1 works fine
    but the DropDownList2 never returns true when it compares against Femina please help me with the reason behind this
    sorry for the lengthy question and thanks in advance
  • cloud255
    Recognized Expert Contributor
    • Jun 2008
    • 427

    #2
    Off the top of my head, string.equals() is case sensitive, so check for that. maybe making everything lower case will help:

    Code:
    bool b = ls.Text.toLower().Equals(testString.toLower());

    Comment

    • femina
      New Member
      • Dec 2007
      • 35

      #3
      i checked it out sir(with my Employee table also),
      its Femina only
      no problem with the case

      Comment

      • cloud255
        Recognized Expert Contributor
        • Jun 2008
        • 427

        #4
        Is it possible that "Femina", your first entry, is not part of the dataset which is returned from the database? Have you created a break point before the loop starts and verified that "Femina" is indeed in in the drop down list?

        It's very strange that all the other names work and this one doesn't ...

        Comment

        • femina
          New Member
          • Dec 2007
          • 35

          #5
          sir i sorted out the problem
          my SQLSERVER Employee table had empname datatype as nchar(10)
          so Femina had still 4 spaces after the word
          i changed it to nvarchar(25) and the problem was sorted out
          thanks for the attention given to my question

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by femina
            sir i sorted out the problem
            my SQLSERVER Employee table had empname datatype as nchar(10)
            so Femina had still 4 spaces after the word
            i changed it to nvarchar(25) and the problem was sorted out
            thanks for the attention given to my question
            Some people make it a point to always TRIM the data before any string comparisons.

            Comment

            • femina
              New Member
              • Dec 2007
              • 35

              #7
              so my table design also does not need to be modified
              thanks so much

              Comment

              Working...