二级联动菜单 两个 DropDownList控件,是联动菜单,想让第二个DropDownList控件点击时候触发SelectedIndexChanged事件,但是没有反应,不知道怎么回事,请指教 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个用JS做就好了http://zxe-llh-163-com.iteye.com/blog/806029 代码如下,联动都OK了,就是第二个DropDownList里显示数据后,我想任点一个把TEXT取出来 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 (!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(); } } protected void DropDownList1_SelectedIndexChanged(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()); System.Data.DataView dv2 = dt.DefaultView; dv2.RowFilter = "PDeptID=" + DropDownList1.SelectedValue; DropDownList2.DataSource = dv2; DropDownList2.DataTextField = "DeptName"; DropDownList2.DataValueField = "PDeptID"; DropDownList2.DataBind(); Session["Temp_Name1"] = DropDownList1.SelectedItem.Text; string Temp_Class = "select * from IP_LocalAllot where [DeptName] = '" + Session["Temp_Name1"] + "'"; SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["ythzhConnectionString"].ConnectionString); SqlCommand scom = new SqlCommand(Temp_Class, con); con.Open(); scom.ExecuteNonQuery(); SqlDataReader CN; CN = scom.ExecuteReader(); while (CN.Read()) { Label1.Text = CN["ID"].ToString(); //取出单位ID(用来赋值给PID) } con.Close(); string T_ID = Label1.Text.Trim(); //录入数据时把T_ID赋值给数据表IP_LocalAllot里的PID } protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e) { // 把相对应的下级单位名称赋值给数据表IP_LocalAllot里的DeptName Label2.Text = DropDownList2.SelectedValue; string T_Name = Label2.Text.Trim(); } 检查autopostback是否为true DropDownList2.AutoPostBack = true; DropDownList2.AutoPostBack = true;知道是这个,还是不行,不知道哪的问题 菜鸟求教啊,登录问题啊 。大家都来帮我啊急急急急急急急急急急急急急急 Socket的Listen方法的连接最大数的问题 用C#可不可以创建黑白的位图对象???? 初手问题,高手进来抠分! 关于C#的问题 数据库冲突? 再说combobox的绑定问题 做过客户证书验证的都请进来!参与有分! 请大家提供点水晶报表在web中运用的例子呢。 Gzipstream使用中出现问题,GZip 头中的幻数不正确。附源码。 取字符 C#如何读取excel并将数据写入到EXCEL中的?
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 (!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();
}
}
protected void DropDownList1_SelectedIndexChanged(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());
System.Data.DataView dv2 = dt.DefaultView;
dv2.RowFilter = "PDeptID=" + DropDownList1.SelectedValue;
DropDownList2.DataSource = dv2;
DropDownList2.DataTextField = "DeptName";
DropDownList2.DataValueField = "PDeptID";
DropDownList2.DataBind();
Session["Temp_Name1"] = DropDownList1.SelectedItem.Text;
string Temp_Class = "select * from IP_LocalAllot where [DeptName] = '" + Session["Temp_Name1"] + "'";
SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["ythzhConnectionString"].ConnectionString);
SqlCommand scom = new SqlCommand(Temp_Class, con);
con.Open();
scom.ExecuteNonQuery(); SqlDataReader CN;
CN = scom.ExecuteReader(); while (CN.Read())
{
Label1.Text = CN["ID"].ToString(); //取出单位ID(用来赋值给PID)
}
con.Close(); string T_ID = Label1.Text.Trim(); //录入数据时把T_ID赋值给数据表IP_LocalAllot里的PID
} protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
// 把相对应的下级单位名称赋值给数据表IP_LocalAllot里的DeptName Label2.Text = DropDownList2.SelectedValue;
string T_Name = Label2.Text.Trim();
}
DropDownList2.AutoPostBack = true;
知道是这个,还是不行,不知道哪的问题