protected void Page_Load(object sender, EventArgs e) { //Get Teacher using (SqlConnection con = new SqlConnection(Database.ConnectionString.con)) { SqlCommand cmd = new SqlCommand("Select ID,Teacher from Classes", con); con.Open(); Teacher_dropdown.DataSource = cmd.ExecuteReader(); Teacher_dropdown.DataBind(); con.Close(); ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "hello();", true); } //Get Class using (SqlConnection con2 = new SqlConnection(Database.ConnectionString.con)) { SqlCommand cmd1 = new SqlCommand("Select ID,Class from Classes", con2); con2.Open(); Class_dropdown.DataSource = cmd1.ExecuteReader(); Class_dropdown.DataBind(); con2.Close(); ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "hello();", true); } //ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "hello();", true); //object[] getteacher = Main.GetDBValue("Classes","Teacher", new string[] { "Creator" }, new string[] { Session["Username"].ToString() }); //object[] getclass = Main.GetDBValue("Classes", "Class", new string[] { "Creator" }, new string[] { Session["Username"].ToString() }); }
public void filldropdownclass() { SqlConnection con = new SqlConnection(cs); con.Open(); SqlCommand com = new SqlCommand("SELECT Class FROM Tbl_class", con); // table name SqlDataAdapter da = new SqlDataAdapter(com); DataSet ds = new DataSet(); da.Fill(ds); // fill dataset Class_dropdown.DataTextField = ds.Tables[0].Columns["Class"].ToString(); // text field name of table dispalyed in dropdown //subjectdrop.DataTextField = ds.Tables[0].Columns["Subject"].ToString(); // to retrive specific textfield name Class_dropdown.DataSource = ds.Tables[0]; //assigning datasource to the dropdownlist Class_dropdown.DataBind(); //binding dropdownlist con.Close(); Class_dropdown.Items.Insert(0, new ListItem("Select", "NA")); }