protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         if (con.State == ConnectionState.Closed)
         {
             con.Open();
         }
         SqlCommand sqlcmd1 = new SqlCommand("select make from cars  ", con);
         DropDownMake.DataSource = sqlcmd1.ExecuteReader();
         DropDownMake.DataBind();
         con.Close();
         if (con.State == ConnectionState.Closed)
         {
             con.Open();
         }
         SqlCommand sqlcmd2 = new SqlCommand("select model from cars  ", con);
         DropDownModel.DataSource = sqlcmd2.ExecuteReader();
         DropDownModel.DataBind();
         con.Close();
         if (con.State == ConnectionState.Closed)
         {
             con.Open();
         }
         SqlCommand sqlcmd3 = new SqlCommand("select style from cars  ", con);
         DropDownStyle.DataSource = sqlcmd3.ExecuteReader();
         DropDownStyle.DataBind();
         con.Close();
         con.Close();
         if (con.State == ConnectionState.Closed)
         {
             con.Open();
         }
         SqlCommand sqlcmd4 = new SqlCommand("select year from cars  ", con);
         DropDownYear.DataSource = sqlcmd4.ExecuteReader();
         DropDownYear.DataBind();
         con.Close();
     }
 }
Ejemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["name"] == null)
                {
                    Session["prevUrl"] = Request.Url;
                    Response.Redirect("~/loginPage.aspx");
                }
                else
                {
                    string username = Session["name"].ToString();
                    this.Label8.Text = string.Format("Hi {0}", Session["name"].ToString() + "!");

                    string        connString = ConfigurationManager.ConnectionStrings["tomms_prodConnectionString"].ConnectionString;
                    SqlConnection con        = null;

                    try
                    {
                        con = new SqlConnection(connString);
                        /*For State Dropdown Load*/
                        string com = "Select RowID, ast_lvl_ast_lvl  from ast_lvl (nolock)";

                        SqlDataAdapter adpt = new SqlDataAdapter(com, con);
                        DataTable      dt   = new DataTable();
                        adpt.Fill(dt);
                        DropDownState.DataSource = dt;
                        DropDownState.DataBind();
                        DropDownState.DataTextField  = "ast_lvl_ast_lvl";
                        DropDownState.DataValueField = "RowID";
                        DropDownState.DataBind();
                        DropDownState.Items.Insert(0, new ListItem("--Select--", "0"));


                        DropDownDistrict.Items.Insert(0, new ListItem("--Select--", "0"));

                        DropDownDocType.Items.Insert(0, new ListItem("PPM B03 & CHECKLIST", "1"));
                        //  DropDownDocType.Items.Insert(0, new ListItem("PPM CHECKLIST", "2"));//commented by muruganantham
                        DropDownDocType.Items.Insert(0, new ListItem("--Select--", "0"));

                        freq_DropDownList1.Items.Insert(0, new ListItem("--Select--", "0"));
                        freq_DropDownList1.Items.Insert(1, new ListItem("1", "1"));
                        freq_DropDownList1.Items.Insert(2, new ListItem("2", "2"));



                        string com1 = "WITH Years(No , Year) AS  ( SELECT 1, 2013 year UNION ALL  SELECT No+1,year+1 FROM  Years AS d  where   Year < Year(getdate())) SELECT No , Year FROM Years order by year desc";

                        SqlDataAdapter adpt1 = new SqlDataAdapter(com1, con);
                        DataTable      dt1   = new DataTable();
                        adpt1.Fill(dt1);
                        DropDownYear.DataSource = dt1;
                        DropDownYear.DataBind();
                        DropDownYear.DataTextField  = "Year";
                        DropDownYear.DataValueField = "No";
                        DropDownYear.DataBind();
                        DropDownYear.Items.Insert(0, new ListItem("--Select--", "0"));
                    }
                    catch (Exception ex)
                    {
                        //log error
                        //display friendly error to user
                        string msg = "Insert Error:";
                        msg += ex.Message;
                        throw new Exception(msg);
                    }
                    finally
                    {
                        con.Close();
                    }
                }
            }
        }