title: Change textbox value when selecting dropdownlist value
body: <p>I have a dropdownlist control that shows the primary key from a table called model, and a textbox that should show another value(a foreign key) from that same table when I use the dropdownlist.
  Both PK  and FK have a single value.</p>
  
  <p>Since I didn't have a clue how to do this, I used a search method that should be called everytime someone selects a new value from the dropdownlist.</p>
  
  <p>Search code:</p>
  
  <pre><code>Public Function searchArea(ByVal model As String) As String
  
          Dim mycon As New Connection            
  
          Using connection As New SqlConnection(mycon.GetConnectionString())
  
              Using command As New SqlCommand()
  
                  command.Connection = connection
                  command.CommandType = CommandType.Text
                  command.CommandText = "SELECT area FROM model WHERE model= @model"
                  command.Parameters.AddWithValue("@model", model)
                  connection.Open()
  
                  Dim dataReader As SqlDataReader = command.ExecuteReader()
  
                  If (dataReader.Read()) Then
                      Return dataReader.ToString(0)'this query should always have a single value
                  End If
  
                  Return "Nothing"
  
              End Using
  
          End Using
  
      End Function
  </code></pre>
  
  <p>Event code:</p>
  
  <pre><code>Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles DropDownList1.SelectedIndexChanged
          Dim objModel As New ModelDAO 'the class where the method is
          TextBox9.Text = objModel.searchArea(DropDownList1.Text)
      End Sub
  </code></pre>
  
  <p>.</p>
  
  <pre><code>&lt;asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="True"
                      DataSourceID="SqlDataSource1" DataTextField="MODEL" DataValueField="MODEL"&gt;
                      &lt;asp:ListItem Text="-Select-" Value="" /&gt;
                      &lt;/asp:DropDownList&gt;
  &lt;asp:TextBox ID="TextBox9" runat="server" Enabled="False" Height="24px" 
                          Width="219px"&gt;&lt;/asp:TextBox&gt;
  &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" 
              ConnectionString="&lt;%$ ConnectionStrings:DBUserInterfaceConnectionString %&gt;" 
              SelectCommand="SELECT [MODEL] FROM [MODEL]"&gt;
          &lt;/asp:SqlDataSource&gt;
  </code></pre>
  
  <p>But as I thought, it doesn't work, can you help me please?</p>
  
  <p>EDIT: Thanks, now it triggers, but  I'm getting the value: 'S' that value doesn't belong to my table.Can you tell me if my search method is ok?</p>