コード例 #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        role = (string)Session["role"];
        if (!this.IsPostBack)
        {
            role = "";
            DropDownListID.DataSource = SqlDataSource1;
            DropDownListID.DataBind();
            DropDownListID.Items.Add(new ListItem("Select ID"));
            DropDownListID.ClearSelection();
            DropDownListID.Items.FindByValue("Select ID").Selected = true;

            DropDownListClass.DataSource = SqlDataSource2;
            DropDownListClass.DataBind();
            DropDownListClass.Items.Add(new ListItem("Select Class"));
            DropDownListClass.ClearSelection();
            DropDownListClass.Items.FindByValue("Select Class").Selected = true;

            DropDownListCourse.DataSource = SqlDataSource3;
            DropDownListCourse.DataBind();
            DropDownListCourse.Items.Add(new ListItem("Select Course"));
            DropDownListCourse.ClearSelection();
            DropDownListCourse.Items.FindByValue("Select Course").Selected = true;
        }
        if ((string)Session["user"] == "")
        {
            ClientScript.RegisterStartupScript(Page.GetType(), "alert", "alert('Please log in first');window.location='LoginPage.aspx';", true);
        }
        user = "******" + (string)(Session["user"]);
    }
コード例 #2
0
        protected void GetListPDF()
        {
            string        logopath    = Server.MapPath("~/PDFFolder");
            List <string> listPDFname = new List <string>();

            string[]      listPDFpath;
            List <string> listPDFurl = new List <string>();

            listPDFpath = Directory.GetFiles(@logopath, "*.pdf",
                                             SearchOption.AllDirectories);
            //Create list of url and name
            foreach (string PDFpath in listPDFpath)
            {
                int    found    = PDFpath.IndexOf("PDFFolder");
                string onlyname = PDFpath.Substring(found + 10);
                listPDFname.Add(onlyname);
                listPDFurl.Add("/PDFFolder/" + onlyname);
            }
            DropDownListID.Items.Insert(0, new ListItem("Choose a pdf", ""));
            for (int i = 0; i < listPDFpath.Length; i++)
            {
                DropDownListID.Items.Insert((i + 1), new ListItem(listPDFname[i], listPDFurl[i]));
            }
            DropDownListID.DataBind();
        }
コード例 #3
0
 protected void Page_Load(object sender, EventArgs e)
 {
     DropDownListID.DataTextField = "Name";
     DropDownListID.DataSource    = aDepartmentManagement.GetAllDepartments();
     DropDownListID.DataBind();
 }
コード例 #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string connString    = @" Data Source=(LocalDB)\v11.0;AttachDbFilename='C:\Users\oshri\Documents\Stock scores.mdf';Integrated Security=True;Connect Timeout=30";
                string queryLecturer = "select id_student from student";
                string queryP        = "select name_profession from profession";

                //SqlConnection conn = new SqlConnection(connString);
                //SqlCommand cmdL = new SqlCommand(queryLecturer, conn);
                //conn.Open();
                //SqlCommand SQLCommand = new SqlCommand();
                //cmdL.CommandType = CommandType.Text;
                //SQLCommand.CommandText = queryLecturer;
                //conn.Close();

                using (var conn = new SqlConnection(connString))
                    using (var cmd = new SqlCommand(queryLecturer, conn))
                    {
                        //SqlDataReader reader = new SqlDataReader();
                        conn.Open();
                        using (SqlDataReader reader = cmd.ExecuteReader())
                        {
                            var list = new List <int>();
                            while (reader.Read())
                            {
                                list.Add(reader.GetInt32(0)); // 0 is the column index.
                            }
                            //DropDownList1.DataSource = list;
                            //DropDownList1.DataBind();
                            DropDownListID.DataSource = list;
                            DropDownListID.DataBind();
                            //s =Convert.ToString( DropDownList1.SelectedItem);

                            conn.Close();
                            //list.Clear();
                        }
                    }
                using (var conn = new SqlConnection(connString))
                    using (var cmp = new SqlCommand(queryP, conn))
                    {
                        //SqlDataReader reader = new SqlDataReader();
                        conn.Open();
                        using (SqlDataReader reader = cmp.ExecuteReader())
                        {
                            var list = new List <string>();
                            while (reader.Read())
                            {
                                list.Add(reader.GetString(0)); // 0 is the column index.
                            }
                            DropDownListP.DataSource = list;
                            //DropDownList1.DataSource = list;
                            //DropDownList1.DataSource = list;
                            DropDownListP.DataBind();
                            //DropDownList1.DataBind();
                            //DropDownList1.DataBind();
                            conn.Close();
                            //DropDownListP.Items.Clear();
                        }
                    }
                DropDownListP.Items.Insert(0, new ListItem("בחר מקצוע", ""));
                DropDownListID.Items.Insert(0, new ListItem("בחר ת.ז", ""));
            }
        }