protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string query = "SELECT [level], [G1] FROM [Table1]"; DataTable dt = GetData(query); DropDownList1.DataSource = dt; DropDownList1.DataTextField = "level"; DropDownList1.DataValueField = "level"; DropDownList1.DataBind(); GridView1.DataSource = dt; GridView1.DataBind(); DropDownList1.Items.Insert(0, new ListItem("Select", "")); } } protected void Chart1_Load(object sender, EventArgs e) { DataTable dt = new DataTable(); string connetionString = null; OleDbConnection connection; OleDbDataAdapter oledbAdapter; DataSet ds = new DataSet(); string firstSql = null; string secondSql = null; string strPath = System.IO.Directory.GetCurrentDirectory(); connetionString = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + strPath + "\\DatabaseChart.accdb;" + "Persist Security Info=False;"; firstSql = "SELECT * FROM [Table1]"; secondSql = "SELECT * FROM [Table2]"; connection = new OleDbConnection(connetionString); connection.Open(); oledbAdapter = new OleDbDataAdapter(secondSql, connection); oledbAdapter.Fill(dt); Chart1.DataSource = dt; Chart1.DataBind(); } private static DataTable GetData(string query) { DataTable dt = new DataTable(); string connetionString = null; OleDbConnection connection; OleDbDataAdapter oledbAdapter; DataSet ds = new DataSet(); string firstSql = null; string secondSql= null; string strPath = System.IO.Directory.GetCurrentDirectory(); connetionString = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + strPath + "\\DatabaseChart.accdb;" + "Persist Security Info=False;"; firstSql = "SELECT * FROM [Table1]"; secondSql = "SELECT * FROM [Table2]"; connection = new OleDbConnection(connetionString); connection.Open(); oledbAdapter = new OleDbDataAdapter(firstSql, connection); oledbAdapter.Fill(dt); return dt; } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { if (DropDownList1.SelectedIndex == 1) { DataTable dt = new DataTable(); string connetionString = null; OleDbConnection connection; OleDbDataAdapter oledbAdapter; DataSet ds = new DataSet(); string firstSql = null; string secondSql = null; string strPath = System.IO.Directory.GetCurrentDirectory(); connetionString = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + strPath + "\\DatabaseChart.accdb;" + "Persist Security Info=False;"; firstSql = "SELECT * FROM [Table1]"; secondSql = "SELECT * FROM [Table2]"; connection = new OleDbConnection(connetionString); connection.Open(); oledbAdapter = new OleDbDataAdapter(secondSql, connection); oledbAdapter.Fill(dt); GridView1.DataSource = dt; GridView1.DataBind(); }
Quote:DropDownList1_SelectedIndexChanged
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง