Пример #1
0
 protected void course_changed(object sender, EventArgs e)
 {
     try {
         SectionDropDown.Items.Clear();
         SectionDropDown.Items.Add(new ListItem("--Select Section--", ""));
         SectionDropDown.AppendDataBoundItems = true;
         SqlSection.SelectCommand             = "select section_id from section as s " +
                                                "where s.course_id = '" + CourseDropdown.SelectedValue + "'";
         SectionDropDown.DataTextField  = "section_id";
         SectionDropDown.DataValueField = "section_id";
         SectionDropDown.DataBind();
         //if (SectionDropDown.Items.Count >= 1)
         //{
         //    SectionDropDown.Enabled = true;
         //}
         //else
         //{
         //    SectionDropDown.Enabled = false;
         //}
     }
     catch (Exception ex)
     {
         throw new ApplicationException("Sorry for the inconvenience", ex);
     }
 }
    public void LoadSectionDropDownList()
    {
        string companyName, departmentName;

        try
        {
            string connectionString = ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString;
            using (SqlConnection con = new SqlConnection(connectionString))
            {
                SqlCommand cmd = new SqlCommand("SELECT * from AuditProgram where ([PID]=@PID)", con);
                con.Open();
                cmd.Parameters.AddWithValue("@PID", Session["ProgramID"]);
                SqlDataReader dr = cmd.ExecuteReader();
                dr.Read();
                companyName    = dr["CompanyName"].ToString();
                departmentName = dr["DepartmentName"].ToString();
            }
            using (SqlConnection con = new SqlConnection(connectionString))
            {
                SqlCommand cmd = new SqlCommand("SELECT * from Section where ([CompanyName]=@CompanyName) AND ([DepartmentName]=@DepartmentName)", con);
                con.Open();
                cmd.Parameters.AddWithValue("@CompanyName", companyName);
                cmd.Parameters.AddWithValue("@DepartmentName", departmentName);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataSet        ds = new DataSet();
                da.Fill(ds);                                                                     // fill dataset
                SectionDropDown.DataTextField  = ds.Tables[0].Columns["SectionName"].ToString(); // text field name of table dispalyed in dropdown
                SectionDropDown.DataValueField = ds.Tables[0].Columns["SectionName"].ToString(); // to retrive specific  textfield name
                SectionDropDown.DataSource     = ds.Tables[0];                                   //assigning datasource to the dropdownlist
                SectionDropDown.DataBind();                                                      //binding dropdownlist
            }
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message + " Section Drop Down");
        }
    }
 public void UpdateSection()
 {
     SectionDropDown.DataBind();
 }
 public void UpdateSection()
 {
     SqlDataSource2.DataBind();
     SectionDropDown.DataBind();
 }