dgrdtype为影片的大分类
dropdownlist为大分类下的小分类
dgrdlxp为影片的具体信息
主要实现功能:
1.第一次调入页面时没有选择大分类活小分类时,显示所有的小分类以及所有的影片的信息,以分页显示
2.选择了大分类时,显示所有当前大分类的影片内容,并且再dropdowmlist中显示对应的小分类,以分页方式
3.选择小分类时,显示所有的当前小分类的影片内容,以分页方式显示
因为我有用到缓存,所以总觉得有些地方不是很对
请大家帮我看看,以下为我的代码:Imports System
Imports System.Data
Imports System.Data.SqlClientPublic Class lxpa Inherits System.Web.UI.Page#Region " Web 窗体设计器生成的代码 " '该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub
Protected WithEvents dgrdtype As System.Web.UI.WebControls.DataList
Protected WithEvents dgrdlxp As System.Web.UI.WebControls.DataGrid
Protected WithEvents Dropstype As System.Web.UI.WebControls.DropDownList
Protected WithEvents stype As System.Web.UI.WebControls.Button '注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub#End Region Dim dstlxp As DataSet
Dim dview1 As DataView
Dim dview2 As DataView
Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码 Dim sc As SqlConnection
Dim dadlxp As SqlDataAdapter
Dim cmdselect As SqlCommand
Dim dtrstype As SqlDataReader '将表type,lxp缓存到一个dataset中
dstlxp = New DataSet
sc = New SqlConnection("server=127.0.0.1;uid=vod;pwd=vod;database=vod")
dadlxp = New SqlDataAdapter("select typeid,type from type", sc)
dadlxp.Fill(dstlxp, "type")
dadlxp.SelectCommand = New SqlCommand("select * from view_lxp", sc)
dadlxp.Fill(dstlxp, "view_lxp")
dadlxp.SelectCommand = New SqlCommand("select stypeid,stype from stype", sc)
dadlxp.Fill(dstlxp, "stype")
dview1 = dstlxp.Tables("view_lxp").DefaultView
If Not IsPostBack Then
'如果非回传,则绑定dgrdtype值
dgrdtype.DataSource = dstlxp
dgrdtype.DataMember = "type"
dgrdtype.DataBind() dview2 = dstlxp.Tables("stype").DefaultView
Dropstype.DataSource = dview2
Dropstype.DataTextField = "stype"
Dropstype.DataBind()
'如果第一次载入页面则绑定dgrdlxp的值
dview1 = dstlxp.Tables("view_lxp").DefaultView
dgrdlxp.DataSource = dview1
Cache("lxp") = dview1
dgrdlxp.DataBind()
End If
End Sub
'选择了分类后,执行此子例程
'为表lxp创建一个dataview,只显示此分类电影,绑定到dgrdlxp控件
Sub dgrdtype_itemcommand(ByVal s As Object, ByVal e As DataListCommandEventArgs)
Dim sc As SqlConnection
Dim cmdselect As SqlCommand
Dim dtrstype As SqlDataReader
Dim strtype
Dim stype '点击条目后重新绑定dgrdlxp的值
Cache.Remove("lxp")
dgrdlxp.CurrentPageIndex = 0
dgrdtype.SelectedIndex = e.Item.ItemIndex
strtype = dgrdtype.DataKeys(e.Item.ItemIndex) dview1 = dstlxp.Tables("view_lxp").DefaultView
dview1.RowFilter = "type='" & strtype & "'" dgrdlxp.DataSource = dview1
Cache("lxp") = dview1
dgrdlxp.DataBind()
'点击条目后重新绑定droplist的值
sc = New SqlConnection("server=127.0.0.1;uid=vod;pwd=vod;database=vod")
sc.Open()
cmdselect = New SqlCommand("select stype from view_stype where type=@strtype", sc)
cmdselect.Parameters.Add("@strtype", strtype)
dtrstype = cmdselect.ExecuteReader() Dropstype.DataSource = dtrstype
Dropstype.DataTextField = "stype"
Dropstype.DataBind()
End Sub Sub Dropstype_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Dropstype.SelectedIndexChanged
'点击了droplist后再次过滤dview1的值,重新绑定dgrdlxp
Dim stype stype = Dropstype.SelectedValue
dgrdlxp.CurrentPageIndex = 0
dview1 = Cache("lxp")
If dview1 Is Nothing Then
dview1 = dstlxp.Tables("view_lxp").DefaultView
End If
dview1.RowFilter = "stype='" & stype & "'" dgrdlxp.DataSource = dview1
Cache("lxp") = dview1
dgrdlxp.DataBind() End Sub
Function getlxp() As DataView
Dim dview1 As DataView
dview1 = Cache("lxp")
Return dview1
End Function
Sub dgrdlxp_pageindexchanged(ByVal s As Object, ByVal e As DataGridPageChangedEventArgs)
dgrdlxp.CurrentPageIndex = e.NewPageIndex
dgrdlxp.DataSource = getlxp()
dgrdlxp.DataBind() End Sub Private Sub stype_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles stype.Click End Sub
End Class
dropdownlist为大分类下的小分类
dgrdlxp为影片的具体信息
主要实现功能:
1.第一次调入页面时没有选择大分类活小分类时,显示所有的小分类以及所有的影片的信息,以分页显示
2.选择了大分类时,显示所有当前大分类的影片内容,并且再dropdowmlist中显示对应的小分类,以分页方式
3.选择小分类时,显示所有的当前小分类的影片内容,以分页方式显示
因为我有用到缓存,所以总觉得有些地方不是很对
请大家帮我看看,以下为我的代码:Imports System
Imports System.Data
Imports System.Data.SqlClientPublic Class lxpa Inherits System.Web.UI.Page#Region " Web 窗体设计器生成的代码 " '该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub
Protected WithEvents dgrdtype As System.Web.UI.WebControls.DataList
Protected WithEvents dgrdlxp As System.Web.UI.WebControls.DataGrid
Protected WithEvents Dropstype As System.Web.UI.WebControls.DropDownList
Protected WithEvents stype As System.Web.UI.WebControls.Button '注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub#End Region Dim dstlxp As DataSet
Dim dview1 As DataView
Dim dview2 As DataView
Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码 Dim sc As SqlConnection
Dim dadlxp As SqlDataAdapter
Dim cmdselect As SqlCommand
Dim dtrstype As SqlDataReader '将表type,lxp缓存到一个dataset中
dstlxp = New DataSet
sc = New SqlConnection("server=127.0.0.1;uid=vod;pwd=vod;database=vod")
dadlxp = New SqlDataAdapter("select typeid,type from type", sc)
dadlxp.Fill(dstlxp, "type")
dadlxp.SelectCommand = New SqlCommand("select * from view_lxp", sc)
dadlxp.Fill(dstlxp, "view_lxp")
dadlxp.SelectCommand = New SqlCommand("select stypeid,stype from stype", sc)
dadlxp.Fill(dstlxp, "stype")
dview1 = dstlxp.Tables("view_lxp").DefaultView
If Not IsPostBack Then
'如果非回传,则绑定dgrdtype值
dgrdtype.DataSource = dstlxp
dgrdtype.DataMember = "type"
dgrdtype.DataBind() dview2 = dstlxp.Tables("stype").DefaultView
Dropstype.DataSource = dview2
Dropstype.DataTextField = "stype"
Dropstype.DataBind()
'如果第一次载入页面则绑定dgrdlxp的值
dview1 = dstlxp.Tables("view_lxp").DefaultView
dgrdlxp.DataSource = dview1
Cache("lxp") = dview1
dgrdlxp.DataBind()
End If
End Sub
'选择了分类后,执行此子例程
'为表lxp创建一个dataview,只显示此分类电影,绑定到dgrdlxp控件
Sub dgrdtype_itemcommand(ByVal s As Object, ByVal e As DataListCommandEventArgs)
Dim sc As SqlConnection
Dim cmdselect As SqlCommand
Dim dtrstype As SqlDataReader
Dim strtype
Dim stype '点击条目后重新绑定dgrdlxp的值
Cache.Remove("lxp")
dgrdlxp.CurrentPageIndex = 0
dgrdtype.SelectedIndex = e.Item.ItemIndex
strtype = dgrdtype.DataKeys(e.Item.ItemIndex) dview1 = dstlxp.Tables("view_lxp").DefaultView
dview1.RowFilter = "type='" & strtype & "'" dgrdlxp.DataSource = dview1
Cache("lxp") = dview1
dgrdlxp.DataBind()
'点击条目后重新绑定droplist的值
sc = New SqlConnection("server=127.0.0.1;uid=vod;pwd=vod;database=vod")
sc.Open()
cmdselect = New SqlCommand("select stype from view_stype where type=@strtype", sc)
cmdselect.Parameters.Add("@strtype", strtype)
dtrstype = cmdselect.ExecuteReader() Dropstype.DataSource = dtrstype
Dropstype.DataTextField = "stype"
Dropstype.DataBind()
End Sub Sub Dropstype_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Dropstype.SelectedIndexChanged
'点击了droplist后再次过滤dview1的值,重新绑定dgrdlxp
Dim stype stype = Dropstype.SelectedValue
dgrdlxp.CurrentPageIndex = 0
dview1 = Cache("lxp")
If dview1 Is Nothing Then
dview1 = dstlxp.Tables("view_lxp").DefaultView
End If
dview1.RowFilter = "stype='" & stype & "'" dgrdlxp.DataSource = dview1
Cache("lxp") = dview1
dgrdlxp.DataBind() End Sub
Function getlxp() As DataView
Dim dview1 As DataView
dview1 = Cache("lxp")
Return dview1
End Function
Sub dgrdlxp_pageindexchanged(ByVal s As Object, ByVal e As DataGridPageChangedEventArgs)
dgrdlxp.CurrentPageIndex = e.NewPageIndex
dgrdlxp.DataSource = getlxp()
dgrdlxp.DataBind() End Sub Private Sub stype_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles stype.Click End Sub
End Class
我要他帮我指点一下,他也懒得看我的滥代码阿
我要他帮我指点一下,他也懒得看我的滥代码阿
=====================
可怜的孩子!!!
这么长的代码,怎么看呀,我看还是把问题简述吧