Comparing dropdownlist null item

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • brunoss
    New Member
    • Jun 2010
    • 8

    Comparing dropdownlist null item

    I have a combobox with values binded from a database
    I add an empty item in the first index
    Code:
    ddlFichaTipo.DataBind();
    ListItem emptyitem = new ListItem(null, null);
    ddlFichaTipo.Items.Insert(0, emptyitem);
    then i need to check if the item selected is not that one
    Code:
    if(ddlFichaTipo.SelectedValue != null)
    gridselect += " and ficha.FichatipoID = " + ddlFichaTipo.SelectedValue;
    The condition is always true whatever the item is selected. What's wrong?...

    ddlfichatipo is my drop down list.
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Selected value is probably an empty string.
    Did you set a breakpoint and actually look what SelectedValue IS when your empty item is selected?
    Why not use SelectedIndex or SelectedItem or the other more useful properties?

    Comment

    • brunoss
      New Member
      • Jun 2010
      • 8

      #3
      Actually I changed the condition to
      Code:
      if (ddlFichaTipo.SelectedIndex != 0)
      and didn't change a thing... I'm not able to debbug my program actually...

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        You cannot debug it? Is it for an embded system or something?

        Comment

        • GaryTexmo
          Recognized Expert Top Contributor
          • Jul 2009
          • 1501

          #5
          You can always debug your program :) If it's a matter of not having visual studio you can always put logging in. Something I typically do is create a new form with a textbox on it and use it to log messages.

          In fact, I think I'll write a quick insight on it :) Check that section in a bit.

          That said, you can also very easily get Visual Studio. Express Edition (2008 and 2010) is available as a free download from Microsoft. I'd recommend it unless you're unable to for other reasons.

          Comment

          • brunoss
            New Member
            • Jun 2010
            • 8

            #6
            Yes I do have Visual studio indeed. But actually i'm putting breakpoints and it just dont stop. Yes, I know how to put a breakpoint and I think there isn't anything disabling it... I do laugh at myself xD

            Comment

            • brunoss
              New Member
              • Jun 2010
              • 8

              #7
              Well i solved my problem in a weird way but it's working... xD. Thank's for the tips

              Comment

              • Plater
                Recognized Expert Expert
                • Apr 2007
                • 7872

                #8
                What turned out to be the solution/issue?

                Comment

                • brunoss
                  New Member
                  • Jun 2010
                  • 8

                  #9
                  Assigned other events althougth it's not perfect neither the best way of doing it. Ill try to find other one soon.

                  it's doesn't recognise the item after the empty one.
                  Last edited by brunoss; Jun 4 '10, 04:15 PM. Reason: mistaken

                  Comment

                  • brunoss
                    New Member
                    • Jun 2010
                    • 8

                    #10
                    Woot got it just too dummy i was calling a remove duhh xD

                    Just put the first code on the pre render event of dropdownlist and its done.
                    Thanks again.

                    Comment

                    Working...