且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ASP.net webform中的下拉列表主详细信息选择

更新时间:2023-02-11 20:04:45

,oledbConn);
OleDbDataAdapter adaptor1 = new OleDbDataAdapter();

adaptor1.SelectCommand = cmd1;
DataSet ds1 = new DataSet();
adaptor1.Fill(ds1,ProductL1);
PL1.DataSource = ds1.Tables [0]。 DefaultView;
PL1.DataValueField =ID;
PL1.DataTextField =Title;
PL1.DataBind();



}

protected void PL1_SelectedIndexChanged(object sender,EventArgs e)
{

if(IsPostBack)
{
string connString = ConfigurationManager.ConnectionStrings [MSIDConn]。ConnectionString;
OleDbConnection oledbConn = new OleDbConnection(connString);

int aa = 0;
int.TryParse(PL1.SelectedValue,out aa);
OleDbCommand cmd2 =新的OleDb命令(SELECT ID,Parent_ID,Title FROM [ProductL2
", oledbConn); OleDbDataAdapter adaptor1 = new OleDbDataAdapter(); adaptor1.SelectCommand = cmd1; DataSet ds1 = new DataSet(); adaptor1.Fill(ds1, "ProductL1"); PL1.DataSource = ds1.Tables[0].DefaultView; PL1.DataValueField = "ID"; PL1.DataTextField = "Title"; PL1.DataBind(); } protected void PL1_SelectedIndexChanged(object sender, EventArgs e) { if (IsPostBack) { string connString = ConfigurationManager.ConnectionStrings["MSIDConn"].ConnectionString; OleDbConnection oledbConn = new OleDbConnection(connString); int aa = 0; int.TryParse(PL1.SelectedValue, out aa); OleDbCommand cmd2 = new OleDbCommand("SELECT ID ,Parent_ID ,Title FROM [ProductL2


Where Parent_ID = @ parentID,oledbConn);
cmd2.Parameters.AddWithValue(@ parentID,aa);
OleDbDataAdapter adaptor2 = new OleDbDataAdapter();
adaptor2.SelectCommand = cmd2;
DataSet ds2 = new DataSet();
// System.Diagnostics.Debug.Print(cmd2.CommandText);

adaptor2.Fill(ds2,ProductL2);
PL2.DataSource = ds2.Tables [0] .DefaultView;
PL2.DataValueField =ID;
PL2.DataTextField =Title;
PL2.DataBind();
oledbConn.Close();
}



}
}
Where Parent_ID = @parentID ", oledbConn); cmd2.Parameters.AddWithValue("@parentID", aa); OleDbDataAdapter adaptor2 = new OleDbDataAdapter(); adaptor2.SelectCommand = cmd2; DataSet ds2 = new DataSet(); // System.Diagnostics.Debug.Print(cmd2.CommandText); adaptor2.Fill(ds2, "ProductL2"); PL2.DataSource = ds2.Tables[0].DefaultView; PL2.DataValueField = "ID"; PL2.DataTextField = "Title"; PL2.DataBind(); oledbConn.Close(); } } }










引用:

运行此:它只选择P1_1并详细记录ProductL2表,无法选择任何其他ProductL1 ID比P1_1 ...(无法选择P1_2,它会自动重置为P1_1)..在代码中我在做什么重置?请让我知道..

on running this : it only select P1_1 and details records from ProductL2 sheets, unable to select any other ProductL1 ID than P1_1 ... ( can't select P1_2 , it reset to P1_1 automatically ) .. where in code i doing reset? please let me know ..