title: Passing list to the parameters of a sqldatasource
body: <p>I have an arraylist in my code behind that stores the id values of various items that are within a database. Upon clicking a button, I wish to pass these id values to an SQLDataSource to act as a parameter for populating a gridview. Unfortunately, my limited knowledge of VB is hindering me, and I'm confused as to how one would go about doing such a thing.</p>
  
  <p><em>code behind</em></p>
  
  <pre><code>Protected Sub Preview_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Preview_Button.Click
  
      Dim list As New ArrayList
      Dim atLeastOneRowSelected As Boolean = False
      'Iterate through the Devices.Rows property
      For Each row As GridViewRow In GridView1.Rows
          'Access the CheckBox
          Dim cb As CheckBox = row.FindControl("DeviceSelector")
          If cb IsNot Nothing AndAlso cb.Checked Then
              atLeastOneRowSelected = True
              'First, get the device_id for the selected row
              Dim device_id As Integer = _
                  Convert.ToInt32(GridView1.DataKeys(row.RowIndex).Value)
              list.Add(device_id)
          End If
      Next
  
  End Sub
  </code></pre>
  
  <p><em>SQLDataSource within .aspx page</em></p>
  
  <pre><code>&lt;asp:SqlDataSource ID="SqlDataSource3" runat="server"
                  ConnectionString="&lt;%$ ConnectionStrings:LOTOConnectionString %&gt;"
                  SelectCommand="SELECT * FROM [DEVICES] WHERE ([devices_id] = @devices_id)"&gt;
      &lt;SelectParameters&gt;
          &lt;asp:Parameter Name="devices_id" Type="Int32" /&gt;
      &lt;/SelectParameters&gt;
  &lt;/asp:SqlDataSource&gt;
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>After playing around a bit, I have realized that I can form my list into an appropriate SQL string using the join command. So the only portion that I am still not understanding is how to reference the SQLDataSource from my code behind.</p>