在第一页有两个dropdownlist控件和一个确定按钮button
<asp:dropdownlist id="name" runat="server">
<asp:ListItem Selected="True">a</asp:ListItem>
<asp:ListItem>d</asp:ListItem>
<asp:ListItem>g</asp:ListItem>
</asp:dropdownlist>
<asp:dropdownlist id="year" runat="server">
<asp:ListItem Selected="True">b</asp:ListItem>
<asp:ListItem>e</asp:ListItem>
<asp:ListItem>h</asp:ListItem>
</asp:dropdownlist>
<asp:button id="Button1" runat="server" Text="确定" Width="55px" ForeColor="Black"></asp:button>
点击按钮引发转页和参数存放到session事件
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim name,year
name = name.selecteditem.text
year = year.SelectedItem.Text
Session("name") = name
Session("year") = year
Response.Redirect("WebForm2.aspx")
End Sub
第二页
有3个label控件
<asp:label id="Label1" runat="server" Width="52px"></asp:label>
<asp:label id="Label2" runat="server" Width="52px"></asp:label>
<asp:label id="Label3" runat="server" Width="52px"></asp:label>
在页面初始化时,接受name,year的值,并在Label1和Label2中显示。
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim name, year
name = Session("name")
Year = Session("year")
Label1.Text = name + ":"
Label2.Text = year
dbcommand.Fill(dspagedata, "news")
Label3.Text = dspagedata.Tables("news").Rows(0).Item("news")
End Sub
并且,在第二页定义了SqlDataAdapter,SqlConnection对象,连接上数据库,生成DataSet
Protected WithEvents dbcommand As System.Data.SqlClient.SqlDataAdapter
Protected WithEvents dbconn As System.Data.SqlClient.SqlConnection
Protected WithEvents dspagedata As WebApplication4.DataSet
连接数据库scsjk
dbconn=new sqlconnection("server=WWW-INTRA;"&"initialcatalog=scsjk;"&"user id=sjpg;"&"password=123;")
查询news值
dbcommand=new SqlDataAdapter("select news from table1 where year=yearand name=name",dbconn)