本文介绍了两个下拉列表验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在dxe中有4个dwon列表:ASPxComboBox。当我点击第二个下拉列表而不选择第一个下拉列表时它将显示为plase select 1st drop down.how我可以编写逻辑请告诉我



我是什么尝试过:

I have 4 drop dwon lists in dxe:ASPxComboBox. when i click 2nd dropdown with out selecting 1st dropdown it will display as plase select 1st drop down.how can i write the logic please tell me

What I have tried:

推荐答案

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)
        {

        }





描述:当你想选择第二个DDL时,你必须先设置第一个DDL的值。第二个DDL被禁用,直到您选择第一个DDL的值。



希望它能解决您的问题

最好的问候



description: when you want to select 2nd DDL, you have to set a value for the 1st one first. the 2nd DDL is disabled until you have selected the value for 1st one.

hope it solve your problem
best regards


这篇关于两个下拉列表验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 11:20