Based on Country or any Dropdown List value Populate the Next Dropdown Data and Display in textbox ..

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
//using WcfService1;
using WebApplication1.ServiceReference1;
using System.Data.SqlClient;
//using WcfService1;
 
namespace WebApplication1
{
    public partial class _Default : System.Web.UI.Page
    {
       
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                PopulateDataforProductTypeList();
            }
           
        }
 
 
        public void PopulateDataforProductTypeList()
        {
            SqlCommand cmd = new SqlCommand("SELECT Distinct Product_Type FROM Product_Details", new SqlConnection("Data Source=KASUMSPC-001\\SQLEXPRESS;Initial Catalog=TEST_DB;User ID=sa;Password=sanjoykss"));
            cmd.Connection.Open();
 
            SqlDataReader ddlValues;
            ddlValues = cmd.ExecuteReader();
 
             txtProduct_Type.DataSource = ddlValues;
             txtProduct_Type.DataValueField = "Product_Type";
             txtProduct_Type.DataTextField = "Product_Type";
             txtProduct_Type.DataBind();
 
            cmd.Connection.Close();
            cmd.Connection.Dispose();
 
        }
 
        protected void Button1_Click(object sender, EventArgs e)
        {
            ServiceReference1.Service1Client proxy = new ServiceReference1.Service1Client();
         
            string Full_Name = txtFullname.Text;
            string Address = txtAddress.Text;
            int Product_Code = Convert.ToInt32(txtProduct_Code.Text);
            string Product_Type = txtProduct_Type.Text;
            string Product_Name = txtProduct_Name.Text;
            decimal Product_Price = Convert.ToDecimal(txtProduct_Price.Text);
 
            try
            {
                proxy.insert_Product_Details(Full_Name, Address, Product_Code, Product_Type, Product_Name, Product_Price, DateTime.Now);
            }
            catch (Exception ex)
            {
                ex.ToString();
                throw;
            }
           
        }
 
        protected void txtProduct_Type_TextChanged(object sender, EventArgs e)
        {
            var ProductType = txtProduct_Type.Text;
            SqlCommand cmd = new SqlCommand("SELECT Distinct Product_Code FROM Product_Details Where Product_Type= '" + ProductType + "' ", new SqlConnection("Data Source=KASUMSPC-001\\SQLEXPRESS;Initial Catalog=TEST_DB;User ID=sa;Password=sanjoykss"));
            cmd.Connection.Open();
 
            SqlDataReader ddlValues;
            ddlValues = cmd.ExecuteReader();
 
            txtProduct_Code.DataSource = ddlValues;
            txtProduct_Code.DataValueField = "Product_Code";
            txtProduct_Code.DataTextField = "Product_Code";
            txtProduct_Code.DataBind();
 
            //Load += new EventHandler(txtProduct_Code_TextChanged);
            cmd.Connection.Close();
            cmd.Connection.Dispose();
        }
 
        protected void txtProduct_Code_TextChanged(object sender, EventArgs e)
        {
            var ProductCode=txtProduct_Code.Text;
            SqlCommand cmd = new SqlCommand("SELECT Product_Name,Product_Price FROM Product_Details Where Product_Code= '"+  ProductCode +"'  ", new SqlConnection("Data Source=KASUMSPC-001\\SQLEXPRESS;Initial Catalog=TEST_DB;User ID=sa;Password=sanjoykss"));
            cmd.Connection.Open();
            SqlDataReader ddlValues;
            ddlValues = cmd.ExecuteReader();
 
            while (ddlValues.Read())
            {
                txtProduct_Name.Text = ddlValues["Product_Name"].ToString();
                txtProduct_Price.Text = ddlValues["Product_Price"].ToString();
            }
            
            cmd.Connection.Close();
            cmd.Connection.Dispose();
        }
 
       
 
      
        
    }
}