[求助]联动读取问题
如图:
大家一看就知道这是我们经常用到的联动。
现在问题是添加的时候没问题,做修改页面时怎么将这两项从表中读过来?
我只能将一级行业读过来,二级行业怎么也不会跟着读过来。。。。。
代码如下:
if(!IsPostBack)
{
this.BindToddlItemA();
dr=SqlHelper.ExecuteReader(con,CommandType.Text,"select * from [zz114_ActivityInfo] where Id="+Id);
if(dr.Read())
{
txtTitle.Text=dr["Title"].ToString().Trim();
content.Value=dr["Info"].ToString().Trim();
lblIssue.Text=dr["Issue"].ToString().Trim();
this.ddlItemA.SelectedIndex=this.ddlItemA.Items.IndexOf(this.ddlItemA.Items.FindByValue(dr["PItemId"].ToString()));
this.ddlItemC.SelectedIndex=this.ddlItemC.Items.IndexOf(this.ddlItemC.Items.FindByValue(dr["ItemId"].ToString()));
}
dr.Close();
con.Close();
}
private void BindToddlItemA()
{
SqlDataAdapter da=new SqlDataAdapter("SELECT * FROM zz114_SJItem_new WHERE ParentID IS NULL",con);
ds=new DataSet();
da.Fill(ds,"testTable");
ddlItemA.DataSource=ds.Tables["testTable"].DefaultView;
ddlItemA.DataTextField=ds.Tables["testTable"].Columns["ItemName"].ToString();
ddlItemA.DataValueField=ds.Tables["testTable"].Columns["ID"].ToString();
ddlItemA.DataBind();
con.Close();
BindToddlItemC(ddlItemA.SelectedValue.ToString());
}
private void BindToddlItemC(string ClassID)
{
Response.Write(ClassID);
SqlDataAdapter da=new SqlDataAdapter("SELECT * FROM zz114_SJItem_new WHERE ParentID = "+ClassID,con);
DataSet ds=new DataSet();
da.Fill(ds,"testTable");
ddlItemC.DataSource=ds.Tables["testTable"].DefaultView;
ddlItemC.DataTextField=ds.Tables["testTable"].Columns["ItemName"].ToString();
ddlItemC.DataValueField=ds.Tables["testTable"].Columns["ID"].ToString();
ddlItemC.DataBind();
con.Close();
}
private void ddlItemA_SelectedIndexChanged(object sender, System.EventArgs e)
{
BindToddlItemC(ddlItemA.SelectedValue.ToString());
}