예제 #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 DropDownListID_SelectedIndexChanged(object sender, EventArgs e)
    {
        string id = DropDownListID.SelectedValue;
        string role2;

        if (id == "Select ID")
        {
            role = "";
            DropDownListCourse.Visible = false;
            course.Visible             = false;
            DropDownListClass.ClearSelection();
            DropDownListClass.Items.FindByValue("Select Class").Selected = true;
            DropDownListCourse.ClearSelection();
            DropDownListCourse.Items.FindByValue("Select Course").Selected = true;
        }
        else
        {
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
            conn.Open();
            string     uname = "SELECT role FROM UserData WHERE id = '" + id + "'";
            SqlCommand com   = new SqlCommand(uname, conn);
            role2           = com.ExecuteScalar().ToString().Trim();
            role            = role2;
            Session["role"] = role2;
            conn.Close();
            if (role2 == "Teacher")
            {
                DropDownListCourse.Visible      = true;
                RequiredFieldValidator4.Enabled = true;
                course.Visible = true;
            }
            else
            {
                DropDownListCourse.Visible      = false;
                RequiredFieldValidator4.Enabled = false;
                course.Visible = false;
            }
        }
    }