关于Dropdownlist
public void BindGrid()
{
SqlConnection con = new SqlConnection(strConstrin);
con.Open();
sqlString = "select Class from Student";
SqlCommand cmd = new SqlCommand(sqlString, con);
SqlDataAdapter SqlAd = new SqlDataAdapter(cmd);
DataSet Rs = new DataSet();
SqlAd.Fill(Rs);
DropDownList1.DataSource = Rs.Tables[0];
DropDownList1.DataTextField = "Class";
DropDownList1.DataValueField = "Class";
DropDownList1.DataBind();
con.Close();
Rs.Clear();
Rs.Dispose();
}
protected void Button2_Click(object sender, EventArgs e)
{
string claNum =DropDownList1.Text;
LoadMess(claNum);
}
为什么每次选择不同的Dropdownlist的子项时总是出现同一个值,不会改变成别的值
我在做一个查询页面,每次无论查询什么都显示同一个页面,真的很无语啊
------解决方案--------------------if(!isPostBack){
}
------解决方案--------------------DropDownList1.SelectedValue;
------解决方案--------------------是不是每次都触发了 BindGrid,page_load事件中加上
if(!isPostBack)
{
BindGrid();
}
------解决方案--------------------