title: dropdown list Query String Parameter
body: <p>Hello everyone how you guys doing? I have a dropdown list that won't populate data values from database using sql datasource. When i use the code behind, i was able to populate the data to the dropdown list. I dont know how to pass the Query String Parameter using code behind since i am new in asp.net.</p>
  
  <p>This is the code behind:</p>
  
  <pre><code>Imports System.Data.SqlClient
  Partial Class PhotoAlbum
      Inherits System.Web.UI.Page
  
      Dim oConn As New SqlConnection("Data Source=.\SQLEXPRESS;" &amp; _
  "AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;" &amp; _
  "Integrated Security=True;User Instance=True")
  
      Dim oCmd As New SqlCommand()
      Dim oDR As SqlDataReader
  
      Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
          oConn.Open()
          oCmd.CommandText = "SELECT [CategoryID], [Name]  FROM Categories  ORDER BY [Name]"
          oCmd.Connection = oConn
          oDR = oCmd.ExecuteReader()
  
          Me.categories.DataSource = oDR
          Me.categories.DataTextField = "Name"
          Me.categories.DataValueField = "CategoryID"
          Me.categories.DataBind()
  
          oDR.Close()
          oConn.Close()
      End Sub
  End Class
  </code></pre>
  
  <p>I will like to include the following information from sqlDatasource to the codebehind:</p>
  
  <pre><code>SelectCommand="SELECT [CategoryID], [Name] FROM [Categories] WHERE ([UserId] = @UserId) ORDER BY [Name]"&gt; 
      &lt;SelectParameters&gt; 
           &lt;asp:QueryStringParameter Name="UserId" QueryStringField="ID"/&gt;
  </code></pre>
  
  <p>As you can see from the code behind, i was able to add :</p>
  
  <pre><code>"SELECT [CategoryID], [Name]  FROM Categories  ORDER BY [Name]".
  </code></pre>
  
  <p>But i will like to add all of this:</p>
  
  <pre><code>SelectCommand="SELECT [CategoryID], [Name] FROM [Categories] WHERE ([UserId] = @UserId) ORDER BY [Name]"&gt; 
          &lt;SelectParameters&gt; 
  </code></pre>
  
  <p>Thank you guys in advance</p>