How to assign a textbox value in dropdownlistbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yookify
    New Member
    • Mar 2010
    • 14

    How to assign a textbox value in dropdownlistbox

    I want to assign a textbox value to dropdownlistbox ,where it should be updated in my database... Can u please give me some suggestions?

    In textbox the date is assigned. In dropdownlistbox one user name is assigned. I have to set the particular date to one particular user..
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Hi Yookify,

    You're asking a little bit too much.
    I'm not sure what you want to do actually....you have a TextBox and a DropDownList.

    Now where I'm confused is....does the user enter Text into the TextBox and you want to use that to update the DropDownList... .

    Or do you want to set the Text in the TextBox with what the user selected in the DropDownList?

    How does any of this tie into your database?
    When are you supposed to update the database?

    When the user selects an item in the DropDownList? When the user clicks a button????


    Could you please clarify what you're trying to do...and in the mean time check out these articles:

    -Frinny

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Please reply in thread.
      Solving problems over PMs breaks the rules here.

      Originally posted by yookify
      thank u so much for ur reply

      sorry if i asked too much..
      i displayed date in textbox.that date should be assigned to a person in dropdown listbox.dropdow n listbox used to have the name of the person from my database.i done the work with the date and dropdownlistbox ,date and dropdownlistbox is well working.can u please tell me how to assign the particular date to a particular person in droplistbox.i used date using calendar.
      When the user clicks the button to do the update you need to grab the selected value in the DropDownList and grab the date value from the TextBox.

      Once you have these values you can update the database (follow the articles that I previously posted for details on how to do that).

      -Frinny

      Comment

      • yookify
        New Member
        • Mar 2010
        • 14

        #4
        thanks a lot for ur reply...
        sorry i cant get ur ans..can u please be specify...i cant c any msg regarding my ques in net.can u please tell me.how to call that value in dropdownlistbox .for ex:dropdownlist box1.selectedit em.To select an name what i have to specify?

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          Use the DropDownListBox .SelectedValue property to retrieve the value that the user selected.

          Use the TextBox.Text property to retrieve the value that the user entered into the text box.

          Once you've retrieved the values you can update your database.

          Comment

          • yookify
            New Member
            • Mar 2010
            • 14

            #6
            Thank for ur kind reply...But this i have done already.i think u didt get my query,if u dnt mine i will repeat it.textbox and dropdownlistbox is working well.textbox contain date from calendar and dropdownlistbox contains name of the person from my database.what i want to do is,


            i want to update this date to a particular person for that what query i have to write .please reply me....

            database
            sno username password date
            1 a aa NULL
            2 b bb NULL
            3 c cc NULL
            4 d dd NULL
            NULL NULL NULL NULL



            Username is the person name(a,b,c,d) displayed on the dropdownlistbox and date is blank here i have to update date.i tried a lot but not coming..please can u help me

            this the coding to display the username in dropdownlistbox :

            myda = New SqlDataAdapter( "Select * from sample ", connection)
            ds = New DataSet
            myda.Fill(ds, "sample")
            DropDownList1.D ataSource = ds
            DropDownList1.D ataTextField = ds.Tables(0).Co lumns("Username ").ColumnName.T oString()
            DropDownList1.D ataBind()




            i want to know how to connect this date to dropdownlistbox .can u please tell me

            Comment

            • Frinavale
              Recognized Expert Expert
              • Oct 2006
              • 9749

              #7
              I think I understand your problem now....

              You have to update the object that you are using as the data source for the DropDownListBox with the date selected for the person.

              In your case, you are populating the data source (which is a DataSet) from your database.

              This means that in order to update your DropDownListBox you either have to update your database with the value entered...which will result in your DropDownListBox being update since it is retrieving the data from the database.

              Or, if you have cached the data set so that you don't need to make a call to the database between postbacks, you can update the Table within the DataSet that contains the data that you are using for the DropDownListBox .

              -Frinny

              Comment

              • yookify
                New Member
                • Mar 2010
                • 14

                #8
                hai

                Thanks My Problem is Solved

                Comment

                • yookify
                  New Member
                  • Mar 2010
                  • 14

                  #9
                  sorry again problem.please tell me
                  I want to update the date and names to a particular user.i dnt know what is the property to use (listbox) multipleselecti on and that multiple selections should be updated .

                  i used
                  mycmd.CommandTe xt = "Update sample Set DATE ='" & ListBox1.Text & "' where USERNAME='" & DropDownList1.S electedValue & "' "

                  Its working well.that .date is updated into a particular person

                  now how to use listbox
                  mycmd.CommandTe xt = "Update sample Set DATE ='" & ListBox1.Text & "' and NAME ='"& listbox1.select edvalue &"' where USERNAME='" & DropDownList1.S electedValue & "' "

                  Error its telling that near and wrong keyword


                  I just used only listbox not date now
                  mycmd.CommandTe xt = "Update sample Set NAME ='" & listbox1.Select edValue & "'' where USERNAME='" & DropDownList1.S electedValue & "' "

                  it is updating only one selected name from the list.i want to update more than one name to Username


                  database:

                  sno username password date name
                  1 a aa 12/3/09
                  2 b bb 13/3/09
                  3 c cc 12/4/09
                  4 d dd 4/3/10
                  NULL NULL NULL NULL


                  in this using listbox i want to update a list of name for a particular username

                  Can u please help me .how to proceed further

                  Comment

                  • Frinavale
                    Recognized Expert Expert
                    • Oct 2006
                    • 9749

                    #10
                    You should not be creating your SQL statement based on user input directly. You will run into problems (like the one your having now) and you are creating a security hole in your application that opens you up to Sql Injection Attacks.

                    You should be using parameters to supply user provided data in your SQL statements instead.

                    Look over the first database tutorial that I linked you to earlier for examples of how to create SQL commands using parameters to supply the user provided data....or check out the MSDN article on the SqlCommand.Para meters Property for more information and additional examples.

                    -Frinny

                    Comment

                    Working...