droplist1是数据库中读出的,根据droplist1中的选择,droplist2从数据库中选出内容,并填充代码如下
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{ int fid = Convert.ToInt32(DropDownList1.SelectedValue);
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ZZW_OLConnectionString"].ConnectionString);
conn.Open();
SqlDataAdapter myCommand=new SqlDataAdapter("SELECT * from XX_city where City_province='" + fid + "'",conn);
DataSet ds=new DataSet();
myCommand.Fill(ds);
DataView source=new DataView(ds.Tables[0]);
DropDownList2.DataValueField = ds.Tables[0].Columns[0].ToString(); DropDownList2.DataTextField = ds.Tables[0].Columns[1].ToString();
DropDownList2.DataSource=source;
DropDownList2.DataBind(); }
但是我单击确定按钮后,要将droplist2中的内容传到另一个页面 无法实现,无论我选择哪项,droplist2传过去的内容都是一样的。传值语句是:
protected void Button1_Click(object sender, EventArgs e)
{
Response.Cookies["cityId"].Value =DropDownList2.SelectedValue;
Response.Cookies["cityName"].Value = DropDownList2.SelectedItem.Text;
Response.Redirect("index.aspx");
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{ int fid = Convert.ToInt32(DropDownList1.SelectedValue);
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ZZW_OLConnectionString"].ConnectionString);
conn.Open();
SqlDataAdapter myCommand=new SqlDataAdapter("SELECT * from XX_city where City_province='" + fid + "'",conn);
DataSet ds=new DataSet();
myCommand.Fill(ds);
DataView source=new DataView(ds.Tables[0]);
DropDownList2.DataValueField = ds.Tables[0].Columns[0].ToString(); DropDownList2.DataTextField = ds.Tables[0].Columns[1].ToString();
DropDownList2.DataSource=source;
DropDownList2.DataBind(); }
但是我单击确定按钮后,要将droplist2中的内容传到另一个页面 无法实现,无论我选择哪项,droplist2传过去的内容都是一样的。传值语句是:
protected void Button1_Click(object sender, EventArgs e)
{
Response.Cookies["cityId"].Value =DropDownList2.SelectedValue;
Response.Cookies["cityName"].Value = DropDownList2.SelectedItem.Text;
Response.Redirect("index.aspx");
}
解决方案 »
- 动态往table里添加许多同样的行
- Asp.net网页中如何实现不同控件之间的输入法切换(比如中英文)
- 日历控件如何点一次就到下一年或者上一年
- 鼠标右键屏蔽怎么不行?
- 我在DataGrid页眉的0列放了一个DropDownList,怎么才能访问DropDownList的值?
- asp.net中gridview里动态生成的列中的checkbox的选中个数限制问题
- 上传图片到数据库中,如何实现?
- asp.net中附加页面
- 为什么一个按钮加上onclick事件,在上面轻点一下一行!
- 求救,在线等待!!
- 类似于QQ空间的空间是如何实现的?asp.net
- vs2010+win7环境下为何网站一直提示正在连接?
Response.Cookies.Add(id)HttpCookie txt = new HttpCookie("cityId",DropDownList2.SelectedItem.Text);
Response.Cookies.Add(txt )
Response.Cookies只能当前页面使用。参见
http://dotnet.aspx.cc/file/Difference-Response-Cookies-Request-Cookies.aspx