Ali Majed HA
Привет
Если вы имеете в виду, что ищете Cascade DropDownList, то код таков :
код поддержки:
protected void Page_Load(object sender, EventArgs e)
{
gvProduct.DataSourceID = ldsProduct.ID;
if (!IsPostBack)
{
ddlType.AppendDataBoundItems = true;
string strConnection = "Data Source =Ali-HP;Database=EzBuy;Integrated Security=yes";
using (SqlConnection Connection = new SqlConnection(strConnection))
{
String strQuery = "select TypeID, TypeName from PrType";
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = strQuery;
cmd.Connection = Connection;
try
{
cmd.Connection.Open();
ddlType.DataSource = cmd.ExecuteReader();
ddlType.DataTextField = "TypeName";
ddlType.DataValueField = "TypeID";
ddlType.DataBind();
}
catch (Exception ex)
{
throw ex;
}
finally
{
cmd.Connection.Close();
cmd.Connection.Dispose();
}
}
}
}
protected void ddlType_SelectedIndexChanged(object sender, EventArgs e)
{
ddlSubType.Items.Clear();
ddlSubType.Items.Add(new ListItem("select Product", ""));
ddlCompany.Items.Clear();
ddlCompany.Items.Add(new ListItem("select company", ""));
ddlSubType.AppendDataBoundItems = true;
string strConnection = "Data Source =Ali-HP;Database=EzBuy;Integrated Security=yes";
using (SqlConnection Connection = new SqlConnection(strConnection))
{
String strQuery = "select SubTypeID, SubTypeName from PrSubType where TypeID=@TypeID ";
SqlCommand cmd = new SqlCommand();
cmd.Parameters.AddWithValue("@TypeID", ddlType.SelectedItem.Value);
cmd.CommandType = CommandType.Text;
cmd.CommandText = strQuery;
cmd.Connection = Connection;
try
{
cmd.Connection.Open();
ddlSubType.DataSource = cmd.ExecuteReader();
ddlSubType.DataTextField = "SubTypeName";
ddlSubType.DataValueField = "SubTypeID";
ddlSubType.DataBind();
if (ddlSubType.Items.Count > 1)
{
ddlSubType.Enabled = true;
}
else
{
ddlSubType.Enabled = false;
ddlCompany.Enabled = false;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
cmd.Connection.Close();
cmd.Connection.Dispose();
}
}
}
protected void ddlSubType_SelectedIndexChanged(object sender, EventArgs e)
{
ddlOS.Items.Clear();
ddlOS.Items.Add(new ListItem("select os", ""));
ddlOS.AppendDataBoundItems = true;
string strConnection = "Data Source =Ali-HP;Database=EzBuy;Integrated Security=yes";
using (SqlConnection Connection = new SqlConnection(strConnection))
{
String strQuery = "select OSID, OSName from PrOS where TypeID=@TypeID ";
SqlCommand cmd = new SqlCommand();
cmd.Parameters.AddWithValue("@TypeID", ddlType.SelectedItem.Value);
cmd.CommandType = CommandType.Text;
cmd.CommandText = strQuery;
cmd.Connection = Connection;
try
{
cmd.Connection.Open();
ddlOS.DataSource = cmd.ExecuteReader();
ddlOS.DataTextField = "OSName";
ddlOS.DataValueField = "OSID";
ddlOS.DataBind();
if (ddlOS.Items.Count > 1)
{
ddlOS.Enabled = true;
}
else
{
ddlOS.Enabled = false;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
cmd.Connection.Close();
cmd.Connection.Dispose();
}
}
}
protected void ddlOS_SelectedIndexChanged(object sender, EventArgs e)
{
ddlCompany.Items.Clear();
ddlCompany.Items.Add(new ListItem("select company", ""));
ddlCompany.AppendDataBoundItems = true;
string strConnection = "Data Source =Ali-HP;Database=EzBuy;Integrated Security=yes";
using (SqlConnection Connection = new SqlConnection(strConnection))
{
String strQuery = "select CompanyID, CompanyName from PrCompany where TypeID=@TypeID ";
SqlCommand cmd = new SqlCommand();
cmd.Parameters.AddWithValue("@TypeID", ddlType.SelectedItem.Value);
cmd.CommandType = CommandType.Text;
cmd.CommandText = strQuery;
cmd.Connection = Connection;
try
{
cmd.Connection.Open();
ddlCompany.DataSource = cmd.ExecuteReader();
ddlCompany.DataTextField = "CompanyName";
ddlCompany.DataValueField = "CompanyID";
ddlCompany.DataBind();
if (ddlCompany.Items.Count > 1)
{
ddlCompany.Enabled = true;
}
else
{
ddlCompany.Enabled = false;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
cmd.Connection.Close();
cmd.Connection.Dispose();
}
}
}
protected void ddlCompany_SelectedIndexChanged(object sender, EventArgs e)
{
}
описание: Если вы хотите выбрать 2-й DDL, вы должны сначала установить значение для 1-го. 2-й DDL отключается до тех пор, пока вы не выберете значение для 1-го.
надеюсь, это решит вашу проблему
с уважением