Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 从复选框列表中选择复选框后,我需要填充我的gridview_Asp.net_Sql_Vb.net_Gridview_Checkboxlist - Fatal编程技术网

Asp.net 从复选框列表中选择复选框后,我需要填充我的gridview

Asp.net 从复选框列表中选择复选框后,我需要填充我的gridview,asp.net,sql,vb.net,gridview,checkboxlist,Asp.net,Sql,Vb.net,Gridview,Checkboxlist,从复选框列表中选择复选框后,我需要填充我的gridview。我尝试使用循环,如果用户取消选中复选框,我还需要隐藏gridview。我正在使用sql语句来提取数据。sql应该提取与复选框关联的任何数据 '显示所选类别中的书籍 受保护的子chkbListControl\u SelectedIndexChanged(发送方作为对象,e作为System.EventArgs)处理chkListControl.SelectedIndexChanged Dim sqlChecked As String

从复选框列表中选择复选框后,我需要填充我的gridview。我尝试使用循环,如果用户取消选中复选框,我还需要隐藏gridview。我正在使用sql语句来提取数据。sql应该提取与复选框关联的任何数据 '显示所选类别中的书籍 受保护的子chkbListControl\u SelectedIndexChanged(发送方作为对象,e作为System.EventArgs)处理chkListControl.SelectedIndexChanged

    Dim sqlChecked As String = "select * " _
                              & "from Books, Categories " _
                              & "where Categories.CategoryCode=Books.CategoryCode " _
                              & "order by Title;"

    Dim sqlUnChecked As String = "select * from Books where Categories.CategoryCode=Books.CategoryCode;"

    Dim selectedIndex As Integer = chkListControl.SelectedIndex
    Dim i As Integer

    If (selectedIndex <> -1) Then

        For i = 0 To chkListControl.Items.Count - 1

            If chkListControl.Items(i).Selected Then

                gvwBookList.DataSource = ReturnTable(sqlChecked)
                gvwBookList.DataBind()

            Else

                gvwBookList.DataSource = ReturnTable(sqlUnChecked)
                gvwBookList.DataBind()
                gvwBookList.Visible = False

            End If
        Next
    End If

End Sub
Dim sqlChecked As String=“select*”_
&“来自书籍、类别”_
&“其中Categories.CategoryCode=Books.CategoryCode”_
&“按标题排序;”
Dim sqlUnChecked As String=“从图书中选择*,其中Categories.CategoryCode=Books.CategoryCode;”
Dim selectedIndex As Integer=chkListControl.selectedIndex
作为整数的Dim i
如果(选择了索引-1),则
对于i=0到chkListControl.Items.Count-1
如果选择了chkListControl.Items(i.),则
gvwBookList.DataSource=ReturnTable(sqlChecked)
gvwBookList.DataBind()
其他的
gvwBookList.DataSource=ReturnTable(sqlUnChecked)
gvwBookList.DataBind()
gvwBookList.Visible=False
如果结束
下一个
如果结束
端接头

您需要像这样修改sqlchecked

 dim selectedcategories as string=""
  If (selectedIndex <> -1) Then

    For i = 0 To chkListControl.Items.Count - 1

        If chkListControl.Items(i).Selected Then

         if selectedcategories="" then
            selectedcategories=chkListControl.Items(i).value
         else
            selectedcategories &="," & chkListControl.Items(i).value
         end if

        End If
    Next
End If

 dim strSQL as string=""
             if selectedcategories.trim<>"" then
                    strSQL = "select * " _
                          & "from Books, Categories " _
                          & "where Categories.CategoryCode=Books.CategoryCode and                     Categories.CategoryCode in (" & selectedcategories &  ")" _
                          & "order by Title;"
   else
strSQL="select * from Books where Categories.CategoryCode=Books.CategoryCode;"

   end if

            gvwBookList.DataSource = ReturnTable(strSQL)
            gvwBookList.DataBind()
dim selectedcategories as string=“”
如果(选择了索引-1),则
对于i=0到chkListControl.Items.Count-1
如果选择了chkListControl.Items(i.),则
如果选择了Categories=“”,则
selectedcategories=chkListControl.Items(i).值
其他的
selectedcategories&=“,”&chkListControl.Items(i).值
如果结束
如果结束
下一个
如果结束
dim strSQL as string=“”
如果选择Categories.trim“”,则
strSQL=“选择*”_
&“来自书籍、类别”_
&其中Categories.CategoryCode=Books.CategoryCode和Categories.CategoryCode在(“&selectedcategories&”)中_
&“按标题排序;”
其他的
strSQL=“从图书中选择*,其中Categories.CategoryCode=Books.CategoryCode;”
如果结束
gvwBookList.DataSource=ReturnTable(strSQL)
gvwBookList.DataBind()
您可以根据需要修改以上代码