通过选择组合框来筛选列表视图数据
问题描述:
我正在学习ASP.Net开发&试图创建Web应用程序,其中ListView数据应该在ComboBox中完成筛选器选择。我已经做的ListView &绑定它与我的数据库表&试图把组合框过滤器,但得到这个错误通过选择组合框来筛选列表视图数据
(System.Web.HttpException:请求不可用在这种情况下)的输出。
VB代码
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Partial Class VB
Inherits System.Web.UI.Page
Dim query As String
Dim strArea As String = Request.QueryString("Country")
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Me.BindListView()
End If
End Sub
Private Sub BindListView()
Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand()
cmd.CommandText = "SELECT CustomerId, ContactName, Country FROM Customers"
cmd.Connection = con
Using sda As New SqlDataAdapter(cmd)
Dim dt As New DataTable()
sda.Fill(dt)
lvCustomers.DataSource = dt
lvCustomers.DataBind()
End Using
End Using
End Using
End Sub
Protected Sub OnPagePropertiesChanging(sender As Object, e As PagePropertiesChangingEventArgs)
TryCast(lvCustomers.FindControl("DataPager1"), DataPager).SetPageProperties(e.StartRowIndex, e.MaximumRows, False)
Me.BindListView()
End Sub
Protected Sub country_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles country.SelectedIndexChanged
Try
If country.SelectedValue <> "All" Then
query = "Select CutomerId, Contact Name, Country from Customers where Country like '%" + strArea + "%' order by rank;"
End If
Dim cmd As New SqlCommand(query)
Dim da As New SqlDataAdapter(cmd)
Dim table As New DataTable
Catch ex As Exception
End Try
End Sub
End Class
答
Request
只读属性属于Page
类继承的类成员只有它继承它(在你的情况VB
)类的成员中是可用的。改变你的代码是这样的: -
Partial Class VB
Inherits System.Web.UI.Page
Dim query As String
Dim strArea As String = String.Empty
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Me.BindListView()
End If
strArea = Request.QueryString("Country")
End Sub
而且,请注意,这将是更好的检查,如果分配给它之前,你的查询字符串变量中存在的任何值。
感谢您的帮助,但它将如何过滤组合框中的选项选项列表视图数据? – 2015-03-03 07:19:09
@SuRajPrince - 我已经回答你的异常消息。要回答你的过滤问题,你写了哪些代码?我无法弄清楚,请张贴你卡在哪里。 – 2015-03-03 07:35:13
我已经通过引用其他教程,但通过从组合框中选择任何选项编写组合代码listview不显示过滤的数据它只是工作页面刷新。基本上我想要的是从组合框的下拉选择只有欲望结果应该来。请看我的问题(代码部分)最后一节我已经编写了代码进行过滤。 – 2015-03-03 07:43:52