我的代碼後面有一個ArrayList,用於存儲數據庫中各種項目的ID值。點擊按鈕後,我希望將這些ID值傳遞給SQLDataSource,以充當填充gridview的參數。不幸的是,我對VB的有限知識阻礙了我,我對如何去做這樣的事情感到困惑。將列表傳遞給sqldatasource的參數
代碼背後的.aspx頁
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:LOTOConnectionString %>"
SelectCommand="SELECT * FROM [DEVICES] WHERE ([devices_id] = @devices_id)">
<SelectParameters>
<asp:Parameter Name="devices_id" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
編輯
內
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
的SqlDataSource了一下週圍打後,我意識到,我可以我的形成列入適當的SQL字符串usi加入連接命令。所以我仍然不理解的唯一部分是如何從後面的代碼中引用SQLDataSource。