两个droplist,droplist2中的内容根据droplist1改变而改变
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");
}
------解决方案--------------------你是不是将DropDownList2的AutoPostBack属性也设置成了True了啊???
------解决方案--------------------
HttpCookie id = new HttpCookie("cityId",DropDownList2.SelectedValue);
Response.Cookies.Add(id)
HttpCookie txt = new HttpCookie("cityId",DropDownList2.SelectedItem.Text);
Response.Cookies.Add(txt )
------解决方案--------------------Response.Cookies和Request.Cookies是有区别的,
Response.Cookies只能当前页面使用。参见
http://dotnet.aspx.cc/file/Difference-Response-Cookies-Request-Cookies.aspx