How to display label text when a dropdown list is selected..

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • arunbojan
    New Member
    • Jul 2008
    • 30

    How to display label text when a dropdown list is selected..

    Hi friends,

    following is my code

    Code:
    //================
    					if (ddlColumnName.SelectedItem.Text == "call duration")
    					{
    						Label4.Text = "HH:MM:SS";
    					}
    					//=================
    Im using c#, i have one dropdown list with n number of items. one amoung that item is call duration. If user select this option i have to display a label, say hh:mm:ss

    can any one advice me the code and where exactly it should be placed.

    Thanks in advance :)
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    SelectedIndexCh anged event for your dropdown.

    Comment

    • arunbojan
      New Member
      • Jul 2008
      • 30

      #3
      yes i have placed under SelectedIndexCh anged event but still label value is not displayed..... Anything wrong in my code ?

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by arunbojan
        yes i have placed under SelectedIndexCh anged event but still label value is not displayed..... Anything wrong in my code ?
        Post the full code you used.

        Comment

        • arunbojan
          New Member
          • Jul 2008
          • 30

          #5
          Following is the code

          Code:
          private void ddlColumnName_SelectedIndexChanged(object sender, System.EventArgs e)
          		{
          						if (ddlColumnName.SelectedItem.Text == "call duration")
          			{
          				Label4.Text = "HH:MM:SS";
          			}
                                            }

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by arunbojan
            Following is the code

            Code:
            private void ddlColumnName_SelectedIndexChanged(object sender, System.EventArgs e)
            		{
            						if (ddlColumnName.SelectedItem.Text == "call duration")
            			{
            				Label4.Text = "HH:MM:SS";
            			}
                                              }
            Output the SelectedItem's Text just to be what it's value actually is. Perhaps they have different case or are different strings altogether.

            Comment

            • Frinavale
              Recognized Expert Expert
              • Oct 2006
              • 9749

              #7
              Originally posted by arunbojan
              Following is the code

              Code:
              private void ddlColumnName_SelectedIndexChanged(object sender, System.EventArgs e)
              		{
              						if (ddlColumnName.SelectedItem.Text == "call duration")
              			{
              				Label4.Text = "HH:MM:SS";
              			}
                                                }
              Just checking: you don't actually have Label4.Visible = false; anywhere do you? If so, you should set Label4.Visible = true; in your SelectedIndexCh anged event.

              -Frinny

              Comment

              • arunbojan
                New Member
                • Jul 2008
                • 30

                #8
                Hi friends i resolved the problem.......


                Code:
                if (ddlColumnName[B].SelectedValue  [/B] == "File size")
                			{
                								Label4.Text = "Bytes";
                			}
                instead of selected value i gave selected text........that was the problem.

                Thank u......

                Comment

                • r035198x
                  MVP
                  • Sep 2006
                  • 13225

                  #9
                  Originally posted by arunbojan
                  Hi friends i resolved the problem.......


                  Code:
                  if (ddlColumnName[b].SelectedValue  [/b] == "File size")
                  			{
                  								Label4.Text = "Bytes";
                  			}
                  instead of selected value i gave selected text........that was the problem.

                  Thank u......
                  If you had output those values as I suggested above you would have picked that up earlier.

                  Comment

                  • tlhintoq
                    Recognized Expert Specialist
                    • Mar 2008
                    • 3532

                    #10
                    I think you will find it a good practice to take text values you are comparing and drop them both to the same case, just to be safe, since comparrisons are case-sensative.

                    Most of mine look like this, keeping the code readible to the coder at the cost of reducing to the smallest number of bytes...

                    if (MyTextBox.Text .ToLower() == "What I Expect".ToLower () )
                    {
                    // Then do something here
                    }

                    This has saved me more than once from my own typos of 'expect' rather than 'Expect' and so on.

                    Comment

                    Working...