所以我一直在开发一个asp.net网站,它有级联下拉列表。我没有使用ajax扩展器进行级联下拉。这是我的项目的html标记
SPOILER,它有很多复选框,这就是为什么我真的需要一个复选框或回发的解决方法..
<form id="form1" runat="server">
<div class = "header" runat = "server">
<div class = "osv"></div>
</div>
<div class = "center">
<div class = "box">
<table id = "spot">
<tr>
<td><asp:Label ID="LBLPlatform" runat="server" Text="Platform :"></asp:Label></td>
<td><asp:DropDownList ID="DDLPlatform" runat="server" CssClass = "ddl" AutoPostBack="True" >
<asp:ListItem Text="Platform" Value="Platform" ></asp:ListItem>
<asp:ListItem Text="First Person" Value="F1"></asp:ListItem>
<asp:ListItem Text="3rd Person" Value="F3"></asp:ListItem>
<asp:ListItem Text="Role Playing" Value="RP"></asp:ListItem>
<asp:ListItem Text="Multiplayer" Value="MP"></asp:ListItem>
<asp:ListItem Text="Single Player" Value="SP"></asp:ListItem>
</asp:DropDownList>
</td>
<td><asp:Label ID="LBLDate" runat="server" Text="Date :"></asp:Label></td>
<td><asp:TextBox ID="DDLDate" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td><asp:Label ID="LBLAgency" runat="server" Text="Agency :"></asp:Label></td>
<td><asp:DropDownList ID="DDLAgency" runat="server" AutoPostBack="true" CssClass = "ddl" >
<asp:ListItem Text="Agency"></asp:ListItem>
</asp:DropDownList></td>
<td><asp:Label ID="LBLReference" runat="server" Text="Reference :"></asp:Label></td>
<td><asp:TextBox ID = "TXTReference" runat = "server"></asp:TextBox></td>
</tr>
<tr>
<td><asp:Label ID="LBLAdvertiser" runat="server" Text="Advertiser :"></asp:Label></td>
<td><asp:DropDownList ID="DDLAdvert" runat="server" AutoPostBack="true" CssClass = "ddl" >
<asp:ListItem Text="Advertiser" ></asp:ListItem>
</asp:DropDownList></td>
<td><asp:Label ID = "LBLProgram" runat = "server" Text = "Program"></asp:Label></td>
<td><asp:DropDownList ID = "DDLProg" runat = "server" CssClass = "ddl"></asp:DropDownList></td>
</tr>
<tr>
<td><asp:Label ID = "LBLProduct" runat = "server" Text = "Product :"></asp:Label></td>
<td><asp:DropDownList ID="DDLProd" runat="server" AutoPostBack="true" CssClass = "ddl" >
<asp:ListItem Text="Product"></asp:ListItem>
</asp:DropDownList></td>
<td><asp:Label ID = "LBLTeldate" runat = "server" Text = "Telecast Date :"></asp:Label></td>
<td><asp:TextBox ID="datepicker" runat="server" onclick="return datepicker_onclick()" AutoPostBack="true" ></asp:TextBox></td>
</tr>
<tr>
<td><asp:Label ID="LBLVerleng" runat="server" Text="Version/Length :"></asp:Label></td>
<td><asp:DropDownList ID="DDLVer" runat="server" CssClass = "ddl" EnableViewState="true" AppendDataBoundItems="True"> </asp:DropDownList>
</td>
<td><asp:Label ID="LBLAe" runat="server" Text="Account Executive :"></asp:Label></td>
<td><asp:TextBox ID="TXTAe" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td><asp:Label ID="LBLCost" runat="server" Text="Cost :"></asp:Label></td>
<td><asp:TextBox ID="TXTCost" runat="server"></asp:TextBox></td>
</tr>
</table>
这是我加载级联ddls的代码
Protected Sub dbchose() Handles DDLPlatform.SelectedIndexChanged
If IsPostBack Then
Select Case DDLPlatform.SelectedValue
Case "Platform"
DDLAgency.DataSource = New List(Of String)
DDLAgency.DataBind()
DDLAgency.Items.Add("Agency")
DDLAdvert.DataSource = New List(Of String)
DDLAdvert.DataBind()
DDLAdvert.Items.Add("Advertiser")
DDLProd.DataSource = New List(Of String)
DDLProd.DataBind()
DDLProd.Items.Add("Product")
DDLVer.DataSource = New List(Of String)
DDLVer.DataBind()
DDLVer.Items.Add("Version - Length")
DDLProg.DataSource = New List(Of String)
DDLProg.DataBind()
DDLProg.Items.Add("Program")
Case "F1"
Session("platform") = "F1"
Dim conn As New SqlConnection(Session("cs").ToString)
Dim que As String = "Select ag_agencde, ag_agennme from agency where ag_stat= 'A' order by ag_agennme asc"
Dim cmd As New SqlCommand(que, conn)
conn.Open() 'loading of agency per platform
DDLAgency.DataSource = cmd.ExecuteReader
DDLAgency.DataTextField = "ag_agennme"
DDLAgency.DataValueField = "ag_agencde"
DDLAgency.DataBind()
conn.Close()
'-- Loading List of Program per Platform - BMS
Dim que2 As String = "select pg_prgcode, pg_prgname from program where pg_status='A' order by pg_prgname ASC"
Dim cmd2 As New SqlCommand(que2, conn)
conn.Open()
DDLProg.DataSource = cmd2.ExecuteReader
DDLProg.DataTextField = "pg_prgname"
DDLProg.DataValueField = "pg_prgcode"
DDLProg.DataBind()
conn.Close()
'--
Case "F3"
Session("platform") = "F3"
Dim conn As New SqlConnection(Session("cs").ToString)
Dim que As String = "Select ag_agencde, ag_agennme from agency where ag_stat='A' order by ag_agennme asc"
Dim cmd As New SqlCommand(que, conn)
conn.Open() 'loading of agency per platform
DDLAgency.DataSource = cmd.ExecuteReader
DDLAgency.DataTextField = "ag_agennme"
DDLAgency.DataValueField = "ag_agencde"
DDLAgency.DataBind()
conn.Close()
'--loading of F3 programs
Dim que2 As String = "select pg_prgcode, pg_prgname from program where pg_status = 'A' order by pg_prgname ASC "
Dim cmd2 As New SqlCommand(que2, conn)
conn.Open()
DDLProg.DataSource = cmd2.ExecuteReader
DDLProg.DataTextField = "pg_prgname"
DDLProg.DataValueField = "pg_prgcode"
DDLProg.DataBind()
'--
Case "RP"
Session("platform") = "RP"
Dim conn As New SqlConnection(Session("cs").ToString)
Dim que As String = "Select ag_agencde, ag_agennme from agency where ag_stat='A' order by ag_agennme asc"
Dim cmd As New SqlCommand(que, conn)
conn.Open()
'--
DDLAgency.DataSource = cmd.ExecuteReader
DDLAgency.DataTextField = "ag_agennme"
DDLAgency.DataValueField = "ag_agencde"
DDLAgency.DataBind()
conn.Close()
'--loading of program per plaform - News TV
Dim que2 As String = "select pg_prgcode, pg_prgname from program where pg_status='A' order by pg_prgname ASC"
Dim cmd2 As New SqlCommand(que2, conn)
conn.Open()
DDLProg.DataSource = cmd2.ExecuteReader
DDLProg.DataTextField = "pg_prgname"
DDLProg.DataValueField = "pg_prgcode"
DDLProg.DataBind()
conn.Close()
'--
Case "MP"
Session("platform") = "Radio"
Dim conn As New SqlConnection(Session("cs").ToString)
Dim que As String = "Select ag_agencde, ag_agennme from agency where ag_stat='A' order by ag_agennme asc"
Dim cmd As New SqlCommand(que, conn)
conn.Open()
'--
DDLAgency.DataSource = cmd.ExecuteReader
DDLAgency.DataTextField = "ag_agennme"
DDLAgency.DataValueField = "ag_agencde"
DDLAgency.DataBind()
conn.Close()
'--loading of program for radio
Dim que2 As String = "select pg_prgcode, pg_prgname from program where pg_stat='A' order by pg_prgname ASC"
Dim cmd2 As New SqlCommand(que2, conn)
conn.Open()
DDLProg.DataSource = cmd2.ExecuteReader
DDLProg.DataTextField = "pg_prgname"
DDLProg.DataValueField = "pg_prgcode"
DDLProg.DataBind()
conn.Close()
'--
Case "SP"
Session("platform") = "SP"
Dim conn As New SqlConnection(Session("cs").ToString)
Dim que As String = "Select ag_agencde, ag_agennme from agency where ag_stat='A' order by ag_agennme asc"
Dim cmd As New SqlCommand(que, conn)
conn.Open()
'--
DDLAgency.DataSource = cmd.ExecuteReader
DDLAgency.DataTextField = "ag_agennme"
DDLAgency.DataValueField = "ag_agencde"
DDLAgency.DataBind()
conn.Close()
'--loading of programs Pinoy TV
Dim que1 As String = "select pg_prgcode, pg_prgname from program where pg_status='A' order by pg_prgname ASC"
Dim cm2 As New SqlCommand(que1, conn)
conn.Open()
DDLProg.DataSource = cm2.ExecuteReader
DDLProg.DataTextField = "pg_prgname"
DDLProg.DataValueField = "pg_prgcode"
DDLProg.DataBind()
End Select
End If
End Sub
Protected Sub agen_choose() Handles DDLAgency.SelectedIndexChanged
If IsPostBack = True Then
Select Case Session("platform").ToString
Case "F1"
Dim que As String = "select ad_advcde, ad_advnme from advertiser where ad_stat='A' order by ad_advnme ASC"
Dim cmd2 As New SqlCommand(que, conn)
conn.Open()
DDLAdvert.DataSource = cmd2.ExecuteReader
DDLAdvert.DataTextField = "ad_advnme"
DDLAdvert.DataValueField = "ad_advcde"
DDLAdvert.DataBind()
conn.Close()
'--
''--
Case "F3"
Dim cs As String = "server=SQLREP;database=F3;uid=sa;password=sa;"
conn.ConnectionString = cs
Dim que As String = "select ad_advcde, ad_advnme from advertiser where ad_stat='A' order by ad_advnme ASC"
Dim cmd2 As New SqlCommand(que, conn)
conn.Open()
DDLAdvert.DataSource = cmd2.ExecuteReader
DDLAdvert.DataTextField = "ad_advnme"
DDLAdvert.DataValueField = "ad_advcde"
DDLAdvert.DataBind()
conn.Close()
'--
Case "RP"
Dim que As String = "select ad_advcde, ad_advnme from RPSA.advertiser where ad_stat='A' order by ad_advnme ASC"
Dim cmd2 As New SqlCommand(que, conn)
conn.Open()
DDLAdvert.DataSource = cmd2.ExecuteReader
DDLAdvert.DataTextField = "ad_advnme"
DDLAdvert.DataValueField = "ad_advcde"
DDLAdvert.DataBind()
conn.Close()
'--
Case "Radio"
Dim que As String = "select ad_advcde, ad_advnme from advertiser where ad_stat='A' order by ad_advnme ASC"
Dim cmd2 As New SqlCommand(que, conn)
conn.Open()
DDLAdvert.DataSource = cmd2.ExecuteReader
DDLAdvert.DataTextField = "ad_advnme"
DDLAdvert.DataValueField = "ad_advcde"
DDLAdvert.DataBind()
conn.Close()
Case "SP"
Dim que As String = "select ad_advcde, ad_advnme from SPSA.advertiser where ad_stat='A' order by ad_advnme ASC"
Dim cmd2 As New SqlCommand(que, conn)
conn.Open()
DDLAdvert.DataSource = cmd2.ExecuteReader
DDLAdvert.DataTextField = "ad_advnme"
DDLAdvert.DataValueField = "ad_advcde"
DDLAdvert.DataBind()
conn.Close()
End Select
End If
End Sub
Protected Sub adver_choose() Handles DDLAdvert.SelectedIndexChanged
Dim conn As New SqlConnection(Session("cs").ToString)
If IsPostBack = True Then
Select Case Session("platform").ToString
Case "F1"
Dim que3 As String = "select p_pcode, p_pname from product where p_stat = 'A' and p_advcde = " & DDLAdvert.SelectedValue & " order by p_pname asc"
Dim cmd3 As New SqlCommand(que3, conn)
conn.Open()
DDLProd.DataSource = cmd3.ExecuteReader
DDLProd.DataTextField = "p_pname"
DDLProd.DataValueField = "p_pcode"
DDLProd.DataBind()
conn.Close()
'--
DDLProd.Items.Add("Product")
'--
Case "F3"
Dim que3 As String = "select p_pcode, p_pname from product where p_stat='A' and p_advcde = " & DDLAdvert.SelectedValue & " order by p_pname asc"
Dim cmd3 As New SqlCommand(que3, conn)
conn.Open()
DDLProd.DataSource = cmd3.ExecuteReader
DDLProd.DataTextField = "p_pname"
DDLProd.DataValueField = "p_pcode"
DDLProd.DataBind()
conn.Close()
'--
DDLProd.Items.Add("Product")
'--
Case "RP"
Dim que3 As String = "select p_pcode, p_pname from RPSA.product where p_stat='A' and p_advcde = " & DDLAdvert.SelectedValue & " order by p_pname asc"
Dim cmd3 As New SqlCommand(que3, conn)
conn.Open()
DDLProd.DataSource = cmd3.ExecuteReader
DDLProd.DataTextField = "p_pname"
DDLProd.DataValueField = "p_pcode"
DDLProd.DataBind()
conn.Close()
'--
DDLProd.Items.Add("Product")
'--
'--
Case "Radio"
Dim que3 As String = "select p_pcode, p_pname from product where p_stat='A' and p_advcde = " & DDLAdvert.SelectedValue & " order by p_pname asc"
Dim cmd3 As New SqlCommand(que3, conn)
conn.Open()
DDLProd.DataSource = cmd3.ExecuteReader
DDLProd.DataTextField = "p_pname"
DDLProd.DataValueField = "p_pcode"
DDLProd.DataBind()
conn.Close()
'--
DDLProd.Items.Add("Product")
'--
'--
Case "SP"
Dim que3 As String = "select p_pcode, p_pname from SPSA.product where p_stat='A' and p_advcde = " & DDLAdvert.SelectedValue & " order by p_pname asc"
Dim cmd3 As New SqlCommand(que3, conn)
conn.Open()
DDLProd.DataSource = cmd3.ExecuteReader
DDLProd.DataTextField = "p_pname"
DDLProd.DataValueField = "p_pcode"
DDLProd.DataBind()
conn.Close()
'--
DDLProd.Items.Add("Product")
'--
End Select
End If
End Sub
Protected Sub get_prod_ver() Handles DDLProd.SelectedIndexChanged
Dim conn As New SqlConnection(Session("cs").ToString)
If Not IsPostBack = True Then
Select Case Session("platform").ToString
Case "F1"
Dim que1 As String = "select v_version +' Lenght:' + convert(varchar(10), v_spotlen) as 'Version And Lenght', v_vpcode from version where v_vpcode = (select p_pcode from product where p_pcode='" & DDLProd.SelectedValue & "')"
Dim cmd4 As New SqlCommand(que1, conn)
conn.Open()
DDLVer.DataSource = cmd4.ExecuteReader
DDLVer.DataTextField = "Version And Lenght"
DDLVer.DataValueField = "v_vpcode"
DDLVer.DataBind()
conn.Close()
DDLVer.Items.Add("Version")
'--
Case "F3"
Dim que1 As String = "select v_version +' Lenght:' + convert(varchar(10), v_spotlen) as 'Version And Lenght', v_vpcode from version where v_vpcode = (select p_pcode from product where p_pcode='" & DDLProd.SelectedValue & "')"
Dim cmd4 As New SqlCommand(que1, conn)
conn.Open()
DDLVer.DataSource = cmd4.ExecuteReader
DDLVer.DataTextField = "Version And Lenght"
DDLVer.DataValueField = "v_vpcode"
DDLVer.DataBind()
conn.Close()
DDLVer.Items.Add("Version")
'--
Case "RP"
Dim que1 As String = "select v_version +' Lenght:' + convert(varchar(10), v_spotlen) as 'Version And Lenght', v_vpcode from RPSA.version where v_vpcode = (select p_pcode from RPSA.product where p_pcode='" & DDLProd.SelectedValue & "')"
Dim cmd4 As New SqlCommand(que1, conn)
conn.Open()
DDLVer.DataSource = cmd4.ExecuteReader
DDLVer.DataTextField = "Version And Lenght"
DDLVer.DataValueField = "v_vpcode"
DDLVer.DataBind()
conn.Close()
'--
DDLVer.Items.Add("Version")
Case "Radio"
Dim que1 As String = "select v_version +' Lenght:' + convert(varchar(10), v_spotlen) as 'Version And Lenght', v_vpcode from version where v_vpcode = (select p_pcode from product where p_pcode='" & DDLProd.SelectedValue & "')"
Dim cmd4 As New SqlCommand(que1, conn)
conn.Open()
DDLVer.DataSource = cmd4.ExecuteReader
DDLVer.DataTextField = "Version And Lenght"
DDLVer.DataValueField = "v_vpcode"
DDLVer.DataBind()
conn.Close()
'--
DDLVer.Items.Add("Version")
Case "SP"
Dim que11 As String = "select v_version +' Lenght:' + convert(varchar(10), v_spotlen) as 'Version And Lenght', v_vpcode from SPSA.version where v_vpcode = (select p_pcode from RPSA.product where p_pcode='" & DDLProd.SelectedValue & "')"
Dim cmd41 As New SqlCommand(que11, conn)
conn.Open()
DDLVer.DataSource = cmd41.ExecuteReader
DDLVer.DataTextField = "Version And Lenght"
DDLVer.DataValueField = "v_vpcode"
DDLVer.DataBind()
conn.Close()
'--
DDLVer.Items.Add("Version")
End Select
Else
Select Session("platform").ToString
Case "F1"
Dim que1 As String = "select v_version +' Lenght:' + convert(varchar(10), v_spotlen) as 'Version And Lenght', v_vpcode from version where v_vpcode = (select p_pcode from product where p_pcode='" & DDLProd.SelectedValue & "')"
Dim cmd4 As New SqlCommand(que1, conn)
conn.Open()
DDLVer.ClearSelection()
DDLVer.DataSource = cmd4.ExecuteReader
DDLVer.DataTextField = "Version And Lenght"
DDLVer.DataValueField = "v_vpcode"
DDLVer.DataBind()
conn.Close()
DDLVer.Items.Add("Version")
'--
Case "F3"
Dim que1 As String = "select v_version +' Lenght:' + convert(varchar(10), v_spotlen) as 'Version And Lenght', v_vpcode from version where v_vpcode = (select p_pcode from product where p_pcode='" & DDLProd.SelectedValue & "')"
Dim cmd4 As New SqlCommand(que1, conn)
conn.Open()
DDLVer.ClearSelection()
DDLVer.DataSource = cmd4.ExecuteReader
DDLVer.DataTextField = "Version And Lenght"
DDLVer.DataValueField = "v_vpcode"
DDLVer.DataBind()
conn.Close()
DDLVer.Items.Add("Version")
'--
Case "RP"
Dim que1 As String = "select v_version +' Lenght:' + convert(varchar(10), v_spotlen) as 'Version And Lenght', v_vpcode from RPSA.version where v_vpcode = (select p_pcode from RPSA.product where p_pcode='" & DDLProd.SelectedValue & "')"
Dim cmd4 As New SqlCommand(que1, conn)
conn.Open()
DDLVer.ClearSelection()
DDLVer.DataSource = cmd4.ExecuteReader
DDLVer.DataTextField = "Version And Lenght"
DDLVer.DataValueField = "v_vpcode"
DDLVer.DataBind()
conn.Close()
'--
DDLVer.Items.Add("Version")
Case "Radio"
Dim que1 As String = "select v_version +' Lenght:' + convert(varchar(10), v_spotlen) as 'Version And Lenght', v_vpcode from version where v_vpcode = (select p_pcode from product where p_pcode='" & DDLProd.SelectedValue & "')"
Dim cmd4 As New SqlCommand(que1, conn)
conn.Open()
DDLVer.ClearSelection()
DDLVer.DataSource = cmd4.ExecuteReader
DDLVer.DataTextField = "Version And Lenght"
DDLVer.DataValueField = "v_vpcode"
DDLVer.DataBind()
conn.Close()
'--
DDLVer.Items.Add("Version")
Case "SP"
Dim que11 As String = "select v_version +' Lenght:' + convert(varchar(10), v_spotlen) as 'Version And Lenght', v_vpcode from SPSA.version where v_vpcode = (select p_pcode from RPSA.product where p_pcode='" & DDLProd.SelectedValue & "')"
Dim cmd41 As New SqlCommand(que11, conn)
conn.Open()
DDLVer.ClearSelection()
DDLVer.DataSource = cmd41.ExecuteReader
DDLVer.DataTextField = "Version And Lenght"
DDLVer.DataValueField = "v_vpcode"
DDLVer.DataBind()
conn.Close()
'--
DDLVer.Items.Add("Version")
End Select
End If
End Sub
我的问题是DDLVer正在重新发送每个POSTBACKS的索引!
如果尝试将if if ispostback放在功能之前没有任何反应但是当我在调试模式下运行它时,vb跳过它并继续结束if。
第二,我尝试使用不同的条件,例如if ispostback = true,如果是ispostback,如果不是ispostback = true,但没有运气..
我一直在开发过去2个月的asp.net页面,而ddlver的这个问题在我的绘图时间表上吃了1个星期..
如果有任何解决方法,请告诉我。
我厌倦了一遍又一遍地阅读相同的文章..
*弓
这是我的页面加载事件
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Page.MaintainScrollPositionOnPostBack = True
DDLVer.AppendDataBoundItems = True
If Not IsPostBack Then
Call sess_load()
Txtto.Enabled = False
Txtbg.Enabled = False
Txtencoded.Enabled = False
DDLDate.Text = Date.Today.Date
Txtfreq.Enabled = False
Txtdate.Enabled = False
Txtto1.Enabled = False
TextBox4.Enabled = False
Txtencoded.Enabled = False
End If
如您所见,我没有绑定任何关于page_load事件的ddl
答案 0 :(得分:0)