触发该控件的事件 ,但是DropDownList控件下拉选择项变换的时候,页面刷新 一下又回到第一条记录了,就是页面在刷新的时候 又回到了第一个索引去了,AutoPostBack属性已经设置成true。 protected void Page_Load(object sender, EventArgs e)
{ string sql = "select * from RTX_Dept";
SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["ythzhConnectionString"].ConnectionString);
SqlCommand scomm = new SqlCommand(sql, conn);
conn.Open();
scomm.ExecuteNonQuery(); DataTable dt = new DataTable();
dt.Load(scomm.ExecuteReader());
if (!Page.IsPostBack)
{
System.Data.DataView dv = dt.DefaultView;
dv.RowFilter = "PDeptID=0";
DropDownList1.DataSource = dv;
DropDownList1.DataTextField = "DeptName";
DropDownList1.DataValueField = "DeptID";
DropDownList1.DataBind();
System.Data.DataView dv2 = dt.DefaultView;
dv2.RowFilter = "PDeptID=" + DropDownList1.SelectedValue;
DropDownList2.DataSource = dv2;
DropDownList2.DataTextField = "DeptName";
DropDownList2.DataValueField = "PDeptID";
DropDownList2.DataBind();
}
}
{ string sql = "select * from RTX_Dept";
SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["ythzhConnectionString"].ConnectionString);
SqlCommand scomm = new SqlCommand(sql, conn);
conn.Open();
scomm.ExecuteNonQuery(); DataTable dt = new DataTable();
dt.Load(scomm.ExecuteReader());
if (!Page.IsPostBack)
{
System.Data.DataView dv = dt.DefaultView;
dv.RowFilter = "PDeptID=0";
DropDownList1.DataSource = dv;
DropDownList1.DataTextField = "DeptName";
DropDownList1.DataValueField = "DeptID";
DropDownList1.DataBind();
System.Data.DataView dv2 = dt.DefaultView;
dv2.RowFilter = "PDeptID=" + DropDownList1.SelectedValue;
DropDownList2.DataSource = dv2;
DropDownList2.DataTextField = "DeptName";
DropDownList2.DataValueField = "PDeptID";
DropDownList2.DataBind();
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货