private void Page_Load(object sender, System.EventArgs e) { if(!Page.IsPostBack) { Bindddl1(); Bindddl2(); } } private void Bindddl1() { Conn c = new Conn(); DropDownList1.DataSource = c.getProvince(); DropDownList1.DataValueField = "ProvinceID"; DropDownList1.DataTextField = "ProvinceName"; DropDownList1.DataBind(); } // เลือกอำเภอที่ตรงกับจังหวัด private void Bindddl2() { Conn c = new Conn(); DropDownList2.DataSource = c.getDistrict(Convert.ToInt32(DropDownList1.SelectedItem.Value)); DropDownList2.DataValueField = "DistrictID"; DropDownList2.DataTextField = "DistrictName"; DropDownList2.DataBind(); } // ตอนเลือกจังหวัด private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e) { // ทำการ Bind อำเภอของจังหวัดที่เลือก Bindddl2(); } ------------------------------------------------------------------------------------- public DataSet getProvince() { string strconn = "Server=(local);database=DB_Name;Trusted_Connection=yes"; SqlConnection conn = new SqlConnection(strconn); string strsql = "select * from province"; SqlDataAdapter da = new SqlDataAdapter(strsql,conn); DataSet ds = new DataSet(); da.Fill(ds,"province"); return ds; } public DataSet getDistrict(int provinceID) { string strconn = "Server=(local);database=DB_name;Trusted_Connection=yes"; SqlConnection conn = new SqlConnection(strconn); string strsql = "select * from district where ProvinceID="+provinceID; SqlDataAdapter da = new SqlDataAdapter(strsql,conn); DataSet ds = new DataSet(); da.Fill(ds,"district"); return ds; }
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง