Question 1:you can use Request.Form["ddl1"] to get your value in page No.2 //in c#if you use vb.net,you may Request.Form("ddl1") to get the valueQuestion 2: you can use selectvalue to realize it
sql = "select sex,sex_id from sex_category" Dim dap4 As New OleDb.OleDbDataAdapter(sql, conn) Dim ds5 As New DataSet() dap4.Fill(ds5, "sex_category") DropDownList1.DataSource = ds5 DropDownList1.DataTextField = "sex" DropDownList1.DataValueField = "sex_id" DropDownList1.DataBind() DropDownList1.Items.Insert(0,"---请选择---"); DropDownList1.Items[0].Value = "nothing";
sql = "select sex,sex_id from sex_category" Dim dap4 As New OleDb.OleDbDataAdapter(sql, conn) Dim ds5 As New DataSet() dap4.Fill(ds5, "sex_category") DropDownList1.DataSource = ds5 DropDownList1.DataTextField = "sex" DropDownList1.DataValueField = "sex_id" DropDownList1.DataBind() DropDownList1.Items.Insert(0,"---请选择---"); DropDownList1.Items[0].Value = "nothing";
Sub Page_Load(sender As Object, e As EventArgs) If Not IsPostBack Then Dim values as ArrayList= new ArrayList() values.Add ("01") values.Add ("02") values.Add ("03") DropDown1.DataSource = values DropDown1.DataBind End If End Sub 第2个问: DropDown1.SelectedIndex=0(默认选项是第一项)
if(!Page.IsPostBack) { sql = "select sex,sex_id from sex_category" Dim dap4 As New OleDb.OleDbDataAdapter(sql, conn) Dim ds5 As New DataSet() dap4.Fill(ds5, "sex_category") DropDownList1.DataSource = ds5 DropDownList1.DataTextField = "sex" DropDownList1.DataValueField = "sex_id" DropDownList1.DataBind() DropDownList1.Items.Insert(0,"---请选择---"); DropDownList1.Items[0].Value = "nothing"; }
url2 = "aa=" + System.Web.HttpUtility.UrlEncode(TextBox1.Text) + ""
url2 = url2 & "&bb=" + System.Web.HttpUtility.UrlEncode(TextBox2.Text) + ""
url2 = url2 & "&ddl1=" + System.Web.HttpUtility.UrlEncode(DropDownList1.SelectedItem.Value) + ""
url2 = url2 & "&ddl2=" + System.Web.HttpUtility.UrlEncode(DropDownList2.SelectedItem.Value) + ""
url2 = url2 & "&ddl3=" + System.Web.HttpUtility.UrlEncode(DropDownList3.SelectedItem.Value) + ""
url2 = url2 & "&ddl8=" + System.Web.HttpUtility.UrlEncode(DropDownList4.SelectedItem.Value) + ""
url2 = url2 & "&ddl9=" + System.Web.HttpUtility.UrlEncode(DropDownList5.SelectedItem.Value) + ""
url = url & url2
Response.Redirect(url)
————————————————————————————
在页面2用request(System.Web.HttpUtility.UrlDecode(ddl1))request(System.Web.HttpUtility.UrlDecode(ddl2))request(System.Web.HttpUtility.UrlDecode(ddl3))request(System.Web.HttpUtility.UrlDecode(ddl4))request(System.Web.HttpUtility.UrlDecode(ddl5))
能介绍介绍吗?
有没有相关文章 ?谢谢
不能确定传递时间,还是用QueryString或Cookies吧!
一、使用Querystring
Querystring是一种非常简单的传值方式,其缺点就是会把要传送的值显示在浏览器的地址栏中,并且在此方法中不能够传递对象。如果你想传递一个安全性不是那么太重要或者是一个简单的数值时,用此方法最好不过了。下面通过一个小例子来完成传值工作,步骤如下:
1、创建一个web form
2、在新建的web form中放置一个button1,在放置两个TextBox1,TextBox2
3、为button按钮创建click事件
代码如下:
private void Button1_Click
(object sender, System.EventArgs e)
{
string url;
url="webform2.aspx?name=" +
TextBox1.Text + "&email=" +
TextBox2.Text;
Response.Redirect(url);
}
4、新建一个目标页面命名为webform2
5、在webform2中放置两个Label1,Label2
在webform2的Page_Load中添加如下代码:
private void Page_Load
(object sender, System.EventArgs e)
{
Label1.Text=Request.QueryString["name"];
Label2.Text=Request.QueryString["email"];
}
运行,即可看到传递后的结果了。二、使用Session变量使用Session变量传值是一种最常见的方式了,此中方式不仅可以把值传递到下一个页面,还可以交叉传递到多个页面,直至把Session变量的值removed后,变量才会消失。举个例子看看:
1、创建一个web form
2、在新建的web form中放置一个button1,在放置两个TextBox1,TextBox2
3、为button按钮创建click事件
代码如下:
private void Button1_Click
(object sender, System.EventArgs e)
{
Session["name"]=TextBox1.Text;
Session["email"]=TextBox2.Text;
Response.Redirect("webform2.aspx");
}
4、新建一个目标页面命名为webform2
5、在webform2中放置两个Label1,Label2
在webform2的Page_Load中添加如下代码:
private void Page_Load
(object sender, System.EventArgs e)
{
Label1.Text=Session["name"].ToString();
Label2.Text=Session["email"].ToString();
Session.Remove("name");
Session.Remove("email");
}
运行,即可看到传递后的结果了。三、使用Server.Transfer
虽然这种方法有点复杂,但也不失为一种在页面传值的方式。
举个例子看看:
1、创建一个web form
2、在新建的web form中放置一个button1,在放置两个TextBox1,TextBox2
3、为button按钮创建click事件
代码如下:
private void Button1_Click
(object sender, System.EventArgs e)
{
Server.Transfer("webform2.aspx");
}
4、创建过程来返回TextBox1,TextBox2控件的值代码如下:
public string Name
{
get
{
return TextBox1.Text;
}
}public string EMail
{
get
{
return TextBox2.Text;
}
}
5、新建一个目标页面命名为webform2
6、在webform2中放置两个Label1,Label2
在webform2的Page_Load中添加如下代码:
private void Page_Load
(object sender, System.EventArgs e)
{
//创建原始窗体的实例
WebForm1 wf1;
//获得实例化的句柄
wf1=(WebForm1)Context.Handler;
Label1.Text=wf1.Name;
Label2.Text=wf1.EMail;}
运行,即可看到传递后的结果了。
您的姓名:<input type="text" name="nickname"><br>
<input type="submit" value="发送">
<form>
a.aspx.cs:
string nickname=Request.QuerySring["nickname"];
1、Request的POST方法
<form action="a.aspx" method="post">
您的姓名:<input type="text" name="nickname"><br>
<input type="submit" value="发送">
<form>
a.aspx.cs:
string nickname=Request.Form["nickname"];
如何给DropDownList指定一个默认的 选择呢?
就是 开始时的默认选择
通过设置以下控件属性指定各列表项应分别用数据源中的哪些字段填充:
DataTextField 其值将显示在列表中的字段的名称。
DataTextFormatString 列表项文本的格式化表达式。
DataValueField 将用于各列表项 Value 属性的字段的名称。
如果数据源只有一个字段,则不必显式设置这些字段,因为控件将只显示这一字段。
那里还有个 seleted属性的,,,选中就可以了
但我还需要加一个默认的无选择
比如---请选择--- VALUES = “无选择”
---DATASET1--- 谢谢 谢谢
values.Add ("KS");
values.Add ("MD");
values.Add ("MI");
values.Add ("OR");
values.Add ("TN"); DropDown1.DataSource = values;
DropDown1.DataBind();
}
values.Add ("KS");
values.Add ("MD");
values.Add ("MI");
values.Add ("OR");
values.Add ("TN"); DropDown1.DataSource = values;
DropDown1.DataBind();
}
Session("ddl2") = DropDownList2.SelectedItem.Value
Session("ddl3") = DropDownList3.SelectedItem.Value
Session("ddl8") = DropDownList8.SelectedItem.Value
Session("ddl9") = DropDownList9.SelectedItem.Value它传递过来的直不是 用户选择的 而是第一个 变量呀我要跳楼了
可以使用Server.Transfer把一个页面提交给另一个页面来处理例如:a.aspx.cs中protected void btn1_Click(object sender,EventArgs e)
{
Server.Transfer("b.aspx",true);
}
b.aspx.cs中Page_Load(object sender,EventArgs e)
{
Response.Write(Request.Form["TextBox1"].ToString()); //TextBox1为a.aspx中的服务器控件
}
你把DropDownList值的绑定过程写在
if (!IsPostBack)
{}
就可以了
你把DropDownList值的绑定过程写在
if (!Page.IsPostBack)
{}
就可以了
你把第一个页面的DropDownList值的绑定过程写在
if (!Page.IsPostBack)
{}
就可以了
Dim dap4 As New OleDb.OleDbDataAdapter(sql, conn)
Dim ds5 As New DataSet()
dap4.Fill(ds5, "sex_category") DropDownList1.DataSource = ds5
DropDownList1.DataTextField = "sex"
DropDownList1.DataValueField = "sex_id"
DropDownList1.DataBind() dap3 = Nothing
<asp:listitem selected>无选择</asp:listitem>
<asp;listitem>01</asp:listitem>
</asp:dropdownlist>
2 无法指定一个默认的DropDownList选择
3 无法从页面2的 QUERYSTRING的到 DropDownList的直 TEXTBOX都可以呀好象一切都是 DLIST的问题请大家帮帮忙呀
<asp:listitem selected>无选择</asp:listitem>
<asp;listitem>01</asp:listitem>
</asp:dropdownlist>这个方法最笨 我早用过了没有用有没有办法 向 DATASET里面直接添加 一个ITEM呢?要具体代码哦
Dim dap4 As New OleDb.OleDbDataAdapter(sql, conn)
Dim ds5 As New DataSet()
dap4.Fill(ds5, "sex_category") DropDownList1.DataSource = ds5
DropDownList1.DataTextField = "sex"
DropDownList1.DataValueField = "sex_id"
DropDownList1.DataBind() DropDownList1.Items.Insert(0,"---请选择---");
DropDownList1.Items[0].Value = "nothing";
Dim dap4 As New OleDb.OleDbDataAdapter(sql, conn)
Dim ds5 As New DataSet()
dap4.Fill(ds5, "sex_category") DropDownList1.DataSource = ds5
DropDownList1.DataTextField = "sex"
DropDownList1.DataValueField = "sex_id"
DropDownList1.DataBind() DropDownList1.Items.Insert(0,"---请选择---");
DropDownList1.Items[0].Value = "nothing";
Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then Dim values as ArrayList= new ArrayList() values.Add ("01")
values.Add ("02")
values.Add ("03") DropDown1.DataSource = values
DropDown1.DataBind
End If
End Sub
第2个问:
DropDown1.SelectedIndex=0(默认选项是第一项)
{
sql = "select sex,sex_id from sex_category"
Dim dap4 As New OleDb.OleDbDataAdapter(sql, conn)
Dim ds5 As New DataSet()
dap4.Fill(ds5, "sex_category") DropDownList1.DataSource = ds5
DropDownList1.DataTextField = "sex"
DropDownList1.DataValueField = "sex_id"
DropDownList1.DataBind() DropDownList1.Items.Insert(0,"---请选择---");
DropDownList1.Items[0].Value = "nothing";
}
是ITEM[0]郁闷呀
{
sql = "select sex,sex_id from sex_category"
Dim dap4 As New OleDb.OleDbDataAdapter(sql, conn)
Dim ds5 As New DataSet()
dap4.Fill(ds5, "sex_category") DropDownList1.DataSource = ds5
DropDownList1.DataTextField = "sex"
DropDownList1.DataValueField = "sex_id"
DropDownList1.DataBind() DropDownList1.Items.Insert(0,"---请选择---");
DropDownList1.Items[0].Value = "nothing";
}