我的代码中有一个数组列表,用于存储数据库中各种项目的 id 值。单击按钮后,我希望将这些 id 值传递给 SQLDataSource 以充当填充网格视图的参数。不幸的是,我对 VB 的有限知识阻碍了我,我对如何去做这样的事情感到困惑。
后面的代码
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
.aspx 页面中的 SQLDataSource
<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>
编辑
玩了一会儿之后,我意识到我可以使用 join 命令将我的列表形成一个合适的 SQL 字符串。所以我仍然不理解的唯一部分是如何从我的代码中引用 SQLDataSource 。