DropDownList控制gridview的问题
大家好,我有两个DropDownList控制gridview。两个DropDownList都有自己的items和一个叫做ALL的选项(值为"")。我想点ALL就没有filter,select所有的东西。问题是有时候一个选ALL,另一个由自己的值(不是ALL)。于是我有了以下的code,我给两个DropDownList各写了一份。
基本思路是:
If both DropDownList have "" value, then select everything
Elseif DropDownList1="" then select everything where value=DropDownList2
Elseif DropDownList2="" then select everything where value=DropDownList1
Endif
当我两个DropDownList都选ALL,顺利得到数据。不动第二个的选项(ALL),把第一个改为其他值,结果什么都没有,没有任何数据,再乱点一下,再点回来就好了,就是很不稳定,时好时坏。是不是AccessDataSourceGridView.SelectParameters.Clear()
除了问题,大家帮帮我,谢谢
Protected Sub DropDownListSchool_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownListProgram.SelectedIndexChanged
If DropDownListSchool.SelectedValue = "" And DropDownListProgram.SelectedValue = "" Then
AccessDataSourceGridView.SelectParameters.Clear()
AccessDataSourceGridView.SelectCommand = "SELECT Students.Username, Students.LastName, Students.FirstName, ProgramsStudents.CourseID, ProgramsStudents.NeedsVisa, Schools.SchoolName, Schools.SchoolID FROM ((Students INNER JOIN ProgramsStudents ON Students.Username = ProgramsStudents.UserName) INNER JOIN Schools ON Students.SchoolID = Schools.SchoolID)"
ElseIf DropDownListSchool.SelectedValue = "" Then
AccessDataSourceGridView.SelectParameters.Clear()
AccessDataSourceGridView.SelectCommand = "SELECT Students.Username, Students.LastName, Students.FirstName, ProgramsStudents.CourseID, ProgramsStudents.NeedsVisa, Schools.SchoolName, Schools.SchoolID FROM ((Students INNER JOIN ProgramsStudents ON Students.Username = ProgramsStudents.UserName) INNER JOIN Schools ON Students.SchoolID = Schools.SchoolID) WHERE (ProgramsStudents.CourseID = '" & DropDownListProgram.SelectedItem.Text & "')"
ElseIf DropDownListProgram.SelectedValue = "" Then
AccessDataSourceGridView.SelectParameters.Clear()
AccessDataSourceGridView.SelectCommand = "SELECT Students.Username, Students.LastName, Students.FirstName, ProgramsStudents.CourseID, ProgramsStudents.NeedsVisa, Schools.SchoolName, Schools.SchoolID FROM ((Students INNER JOIN ProgramsStudents ON Students.Username = ProgramsStudents.UserName) INNER JOIN Schools ON Students.SchoolID = Schools.SchoolID) WHERE (Students.SchoolID = '" & DropDownListSchool.SelectedItem.Text & "')"
End If
End Sub
Protected Sub DropDownListProgram_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownListProgram.SelectedIndexChanged
If DropDownListSchool.SelectedValue = "" And DropDownListProgram.SelectedValue = "" Then
AccessDataSourceGridView.SelectParameters.Clear()
AccessDataSourceGridView.SelectCommand = "SELECT Students.Username, Students.LastName, Students.FirstName, ProgramsStudents.CourseID, ProgramsStudents.NeedsVisa, Schools.SchoolName, Schools.SchoolID FROM ((Students INNER JOIN ProgramsStudents ON Students.Username = ProgramsStudents.UserName) INNER JOIN Schools ON Students.SchoolID = Schools.SchoolID)"
ElseIf DropDownListSchool.SelectedValue = "" Then
AccessDataSourceGridView.SelectParameters.Clear()
AccessDataSourceGridView.SelectCommand = "SELECT Students.Username, Students.LastName, Students.FirstName, ProgramsStudents.CourseID, ProgramsStudents.NeedsVisa, Schools.SchoolName, Schools.SchoolID FROM ((Students INNER JOIN ProgramsStudents ON Students.Username = ProgramsStudents.UserName) INNER JOIN Schools ON Students.SchoolID = Schools.SchoolID) WHERE (ProgramsStudents.CourseID = '" & DropDownListProgram.SelectedItem.Text & "')"
ElseIf DropDownListProgram.SelectedValue = "" Then
AccessDataSourceGridView.SelectParameters.Clear()
AccessDataSourceGridView.SelectCommand = "SELECT Students.Username, Students.LastName, Students.FirstName, ProgramsStudents.CourseID, ProgramsStudents.NeedsVisa, Schools.SchoolName, Schools.SchoolID FROM ((Students INNER JOIN ProgramsStudents ON Students.Username = ProgramsStudents.UserName) INNER JOIN Schools ON Students.SchoolID = Schools.SchoolID) WHERE (Students.SchoolID = '" & DropDownListSchool.SelectedItem.Text & "')"
End If
End Sub
--------------------编程问答-------------------- 沙发
补充:.NET技术 , ASP.NET