DropDown List and TextBox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • murugavelmsc
    New Member
    • Apr 2008
    • 54

    DropDown List and TextBox

    hi,

    in asp.net, i have form with dropdownlist contains a item of productid from the product table. Another item is textbox which is depends upon the dropdownlist.
    whenever a dropdownlist index changed, textbox have a productname of productid.

    thanks in advance,

    Murugavel
  • kusumanjali
    New Member
    • Aug 2008
    • 3

    #2
    Originally posted by murugavelmsc
    hi,

    in asp.net, i have form with dropdownlist contains a item of productid from the product table. Another item is textbox which is depends upon the dropdownlist.
    whenever a dropdownlist index changed, textbox have a productname of productid.

    thanks in advance,

    Murugavel
    hi

    can you please clearly explain whether you need to select or insert the values..

    Anjali

    Comment

    • murugavelmsc
      New Member
      • Apr 2008
      • 54

      #3
      Originally posted by kusumanjali
      hi

      can you please clearly explain whether you need to select or insert the values..

      Anjali
      <asp:DropDownLi st ID="ddprodid" runat="server" Width="135px" DataSourceID="S qlDataSource1" DataTextField=" ProductID" DataValueField= "ProductID" OnSelectedIndex Changed="ddprod id_SelectedInde xChanged">
      </asp:DropDownLis t><asp:SqlDataS ource ID="SqlDataSour ce1" runat="server" ConnectionStrin g="<%$ ConnectionStrin gs:pmgConnectio nString5 %>"
      SelectCommand=" SELECT [ProductID] FROM [Products]"></asp:SqlDataSour ce>

      In textbox, it displays a productname of productid (which is selected from dropdownlist)

      thanks,
      murugavel

      Comment

      • balabaster
        Recognized Expert Contributor
        • Mar 2007
        • 798

        #4
        Originally posted by murugavelmsc
        <asp:DropDownLi st ID="ddprodid" runat="server" Width="135px" DataSourceID="S qlDataSource1" DataTextField=" ProductID" DataValueField= "ProductID" OnSelectedIndex Changed="ddprod id_SelectedInde xChanged">
        </asp:DropDownLis t><asp:SqlDataS ource ID="SqlDataSour ce1" runat="server" ConnectionStrin g="<%$ ConnectionStrin gs:pmgConnectio nString5 %>"
        SelectCommand=" SELECT [ProductID] FROM [Products]"></asp:SqlDataSour ce>

        In textbox, it displays a productname of productid (which is selected from dropdownlist)

        thanks,
        murugavel
        In an ideal world you would grab all your data in one hit - populate the dropdownlist with the selection items and bind the value field to the record's key. Then when you select from the dropdownlist, you would reference the SelectedValue property to grab the relevant field from the SqlDataSource and populate the textbox. This saves a second database call.

        However, since I've not yet had my morning cup of tea, I can't recall how I've done this in the past.

        The alternative way is two SqlDataSources, first one populates the dropdownlist and binds the value field to the key. The second SqlDataSource just gets the info for the textbox using the dropdownlist's SelectedValue property as a control parameter to only select the relevant field. Then you can set the textbox's value using the XHTML notation: <asp:TextBox id="MyTextBox" Value="<%# Field %>" /> or by setting the textbox's text in the Code Behind for the OnDataBinding event of the second SqlDataSource.

        Comment

        Working...