protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Session["PageName"] = "Unsubscribe";

            ServiceReference objServiceReference = new ServiceReference();

            ScriptReference objScriptReference = new ScriptReference();

            objServiceReference.Path = "~/CarsService.asmx";

            objScriptReference.Path = "~/Static/Js/CarsJScriptNew.js";

            scrptmgr.Services.Add(objServiceReference);
            scrptmgr.Scripts.Add(objScriptReference);

            if (Request.QueryString.Keys.Count > 0)
            {
                string URL = string.Empty;
                string URL1 = string.Empty;
                if (Request.QueryString.Keys.Count > 0)
                {
                    if (URL != null)
                    {
                        PreferencesBL objPreferencesBL = new PreferencesBL();

                        DataSet dsPreferences = new DataSet();

                        dsPreferences = objPreferencesBL.GetEmailPreferences(Request.QueryString["PreferID"].ToString());

                        if (dsPreferences.Tables[0].Rows.Count > 0)
                        {
                            if (dsPreferences.Tables[0].Rows[0]["IsActive"].ToString() == "True")
                            {
                                objPreferencesBL.SubScribeStatus(Request.QueryString["PreferID"].ToString(), 0);

                                lblalert.Text = "Email Alerts has Unsubscribed Successfully...";
                            }
                            else
                            {
                                lblalert.Text = "Email Alerts has Already Unsubscribed ";

                                //mpealteruser.Show();
                            }
                        }

                        Type cstype = GetType();
                        ClientScriptManager cs = Page.ClientScript;
                        cs.RegisterStartupScript(cstype, "KyRST", "<script type='text/javascript' language='javascript'>pageLoad();</script>");

                    }
                }

            }

        }
    }
    private void GetEmailPreferences(string PreferenceID)
    {
        PreferencesBL objPreferencesBL = new PreferencesBL();

        DataSet dsPreferences = new DataSet();

        dsPreferences = objPreferencesBL.GetEmailPreferences(PreferenceID);

        if (dsPreferences.Tables[0].Rows.Count > 0)
        {

            if (dsPreferences.Tables[0].Rows[0]["isactive"].ToString() == "0")
            {

                lblalert.Text = "Your email address Already Unsubscribed";

                mpealteruser.Show();

            }
            else
            {

                if (dsPreferences.Tables[0].Rows[0]["Zip"].ToString() != "")
                {
                    txtZip.Text = dsPreferences.Tables[0].Rows[0]["Zip"].ToString();
                }
                if (dsPreferences.Tables[0].Rows[0]["Name"].ToString() != "")
                {
                    txtName.Text = dsPreferences.Tables[0].Rows[0]["Name"].ToString();
                }

                if (dsPreferences.Tables[0].Rows[0]["Email"].ToString() != "Your Email")
                {
                    txtEmailAlert.Text = dsPreferences.Tables[0].Rows[0]["Email"].ToString();
                }

                if (dsPreferences.Tables[0].Rows[0]["Phone"].ToString() != "")
                {
                    txtPhoneNo.Text = dsPreferences.Tables[0].Rows[0]["Phone"].ToString();
                }

                hdnUserPrefernceID.Value = dsPreferences.Tables[0].Rows[0]["UserPreferID"].ToString();

                if (dsPreferences.Tables[1].Rows.Count > 0)
                {

                    int k = 1;

                    TotalRowcount.Value = dsPreferences.Tables[1].Rows.Count.ToString();

                    for (int i = 0; i < dsPreferences.Tables[1].Rows.Count; i++)
                    {

                        DropDownList ddlDropddlMake = (DropDownList)Page.FindControl("ddlMakes" + k);
                        DropDownList ddlDropddlModel = (DropDownList)Page.FindControl("ddlModels" + k);
                        DropDownList ddlDropddlRange = (DropDownList)Page.FindControl("ddlRanges" + k);

                        HiddenField hdnPreferenceID = (HiddenField)Page.FindControl("hdnPreferenceID" + k);

                        ddlDropddlRange.SelectedIndex = -1;

                        ddlDropddlMake.SelectedIndex = ddlDropddlMake.Items.IndexOf(ddlDropddlMake.Items.FindByValue(dsPreferences.Tables[1].Rows[i]["Makeid"].ToString()));

                        GetModelsInfo(ddlDropddlMake.SelectedValue, ddlDropddlModel);

                        ddlDropddlModel.SelectedIndex = ddlDropddlModel.Items.IndexOf(ddlDropddlModel.Items.FindByValue(dsPreferences.Tables[1].Rows[i]["ModelID"].ToString()));

                        //ddlDropddlRange.SelectedIndex = ddlDropddlRange.Items.IndexOf(ddlDropddlRange.Items.FindByValue(dsPreferences.Tables[1].Rows[i]["PriceRange"].ToString()));

                        ddlDropddlRange.SelectedIndex = Convert.ToInt32(dsPreferences.Tables[1].Rows[i]["PriceRange"].ToString());

                        hdnPreferenceID.Value = dsPreferences.Tables[1].Rows[i]["PreferenceID"].ToString();

                        k = k + 1;
                    }
                }
                else
                {
                    TotalRowcount.Value = "1";
                }
            }
        }
    }