DropDownList控件的问题
DropDownList控件的SelectedIndexChanged时间,该怎样写才有效呢,为什么我写了以后,在改变DropDownList控件的选项时总是无效,下面是我写的部分代码,请朋友们帮忙指正一下,谢谢。public partial class _Default : System.Web.UI.Page
{
//连接数据库的字符串
String myConnetionString = "server=E65B726CAB1141D;Initial Catalog=peoples;User ID=Sa;pwd=19830125;";
SqlConnection myConnetion = new SqlConnection();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
repeaterBind();
}
//绑定数据源
private void repeaterBind()
{
myConnetion.ConnectionString = myConnetionString;
string city = DropDownList1.SelectedItem.ToString();
string selectCommend = "SELECT * FROM people_1 WHERE usercity='" + city + "'";
SqlDataAdapter myAdapter = new SqlDataAdapter(selectCommend, myConnetion);
myConnetion.Open();
DataSet mySet = new DataSet();
myAdapter.Fill(mySet, "people_1");
Repeater1.DataSource = mySet;
Repeater1.DataBind();
myConnetion.Close();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) //这个事件到底该怎么写才有效呢?
{
repeaterBind();
}
}