Click here to Skip to main content
15,893,564 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        populatemobile();
    }
}

public DataSet getdata(string sqlquery)
{
    SqlConnection con = new SqlConnection(@"server=DELL\SQLEXPRESS;Trusted_Connection=yes;Initial Catalog=product;");

    SqlDataAdapter da = new SqlDataAdapter(sqlquery, con);

    DataSet ds = new DataSet();

    da.Fill(ds);

    return ds;
}

public void populatemobile()
{
    DataSet ds = getdata("Select * from ITEM_TYPE");

    MOBDropDownList.DataSource = ds;
    MOBDropDownList.DataValueField = "TYPE_ID";
    MOBDropDownList.DataTextField = "MOBILE_NAME";
    MOBDropDownList.DataBind();

    NAMEDropDownList.Enabled = false;

    ListItem limob = new ListItem("Select MOBILE_NAME", "-1");

    MOBDropDownList.Items.Insert(0, limob);

    ListItem liname = new ListItem("Select MOBILE_TYPE", "-1");

    NAMEDropDownList.Items.Insert(0, liname);
}

protected void MOBDropDownList_SelectedIndexChanged(object sender, EventArgs e)
{
    if (MOBDropDownList.SelectedValue == "-1")
    {
        NAMEDropDownList.SelectedIndex = 0;
        NAMEDropDownList.Enabled = false;
    }
    else
    {
        NAMEDropDownList.Enabled = true;
        NAMEDropDownList.DataSource = getdata("Select * from ITEMS where MOBILE_ID = '" + MOBDropDownList.SelectedValue.ToString() + "'");
        NAMEDropDownList.DataTextField = "MOBILE_MODEL";
        NAMEDropDownList.DataValueField = "TYPE_ID";
        NAMEDropDownList.DataBind();

        ListItem liname = new ListItem("Select MOBILE_TYPE", "-1");

        NAMEDropDownList.Items.Insert(0, liname);
    }

    if (NAMEDropDownList.Enabled == true)
    {
        string str = @"server=DELL\SQLEXPRESS;Trusted_Connection=yes;Initial Catalog=product;";

        SqlConnection con = new SqlConnection(str);
        try
        {
            con.Open();

            string query = "select * from ITEMS where TYPE_ID= '" + MOBDropDownList.Text + "' ";

            SqlCommand cmd = new SqlCommand(query, con);

            SqlDataReader dbr;
            dbr = cmd.ExecuteReader();

            while (dbr.Read())
            {
                string price = dbr.GetInt32(1).ToString();
                pricetxtbox.Text = price;
            }
            con.Close();
        }      
        catch (Exception er)
        {
            MessageBox.Show(er.Message);
        }
    }
    else
    {
        string str = @"server=DELL\SQLEXPRESS;Trusted_Connection=yes;Initial Catalog=product;";

        SqlConnection con = new SqlConnection(str);
        try
        {
            con.Open();

            string query = "select * from ITEMS where MOBILE_PRICE= '" + MOBDropDownList.Text + "' ";

            SqlCommand cmd = new SqlCommand(query, con);
            SqlDataReader dbr;
            dbr = cmd.ExecuteReader();

            while (dbr.Read())
            {
                string price = dbr.GetInt32(1).ToString();
                pricetxtbox.Text = price;
            }
            con.Close();
        }
        catch (Exception er)
        {
            MessageBox.Show(er.Message);
        }
    }
}
Posted
Updated 25-Apr-15 21:26pm
v3
Comments
Tomas Takac 26-Apr-15 3:28am    
This is just a code dump. Can you describe where is the problem?
F-ES Sitecore 26-Apr-15 6:17am    
As said you'll need to explain the actual problem in more detail, but you can't use MessageBox.Show in a website. It might on your local machine as the client and server are the same machine, but it won't work when the site is running on a remote server.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900