C # implement the master from DROPDOWNLIST interaction

zhaozj2021-02-16  52

As I believe in me, there are many peers encountered the problem of the main from DropDownList, such as the choice of counties, so that the system automatically lists the histoped list of the people under the county in DropDownList2, and the hometown, then in DropDownList3 List the list of villages in the country, then my previous solution is to re-rill Dataset, which is bound to DROPDOWNLIST, such cost resource, but also trouble, in fact, we can use RowFilter to achieve, the following is my specific implementation method :

Override Protected Void OnNit (Eventargs E) {// // Codegen: This call is required for the ASP.NET Web Form Designer. // InitializeComponent (); base.onit (e); inita ();

// Initialize DORPDOWNLIST

DataSet myds; // cconection For my custom class; implementation with the database, one of which is CNN, which is OLEDBConnection.cconection mycnn; public void inita () {mycn = new cconection (); string strsql; strsql = " select number and name from sys_county order by number "; OleDbDataAdapter MyoleAp = new OleDbDataAdapter (strSql, Mycnn.Cnn); Myds = new DataSet (); MyoleAp.Fill (Myds," sys_county "); this.DropDownList1.DataSource = Myds. Tables [ "sys_county"]; this.DropDownList1.DataValueField = "No"; this.DropDownList1.DataTextField = "name"; this.DropDownList1.DataBind (); strSql = "select number, name, belongs to the county from sys_town order by number "; MyoleAp.SelectCommand.CommandText = strSql; MyoleAp.Fill (myds," sys_town "); this.DropDownList2.DataSource = Myds.Tables [" sys_town "]; this.DropDownList2.DataValueField =" No "; this.DropDownList2. DATATEXTFIELD = "Name"; myoleap.dispose ();

// DropDownList1 Changed changes the display value of DorpdownList2,

转载请注明原文地址:https://www.9cbs.com/read-21949.html

New Post(0)