When doing data queries, you often need to select a field. Discover in actual work, place the field name into the listbox control, then select the field by one or all to the new listbox control, and implement the selection of the table field name. The implementation method is as follows:
Test.aspx ----------------------------- .................
TEST.ASPX.CS -----------------------------
....................
Private void page_load (object sender, system.eventargs e) {// Place user code here to initialize page if (! ispostback) {session ["AAA"] = listbox2.items.count; session ["TableName"] = "Adat_fewf_1"; arraylist rar = getdbcolumn ((string) session ["Tablename"]); for (int i = 0; i private ArrayList GetDBColumn (string TableName) {strConn = GetADBConfig (); strCmd = "SELECT column_name FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '" TableName "'"; Conn = new SqlConnection (strConn); cmd = new SqlCommand (strCmd, Conn ArrayList Marr = new arraylist (); try {conn.open (); sqldataareader DR = cmd.executeReader (); while (Dr.Read ()) Marr.Add (Dr.getstring (0)); Return Marr; } catch (SqlException ex) {Logs.ExpErrorLog errLog = new Logs.ExpErrorLog (errLogFileName, ex.Message); return mArr;} finally {if (! Conn.State = ConnectionState.Closed) Conn.Close ();}} #Region Web Form Designer Generated Code Override Protected Void OnNit (Eventargs E) {// // Codegen: This call is required for the ASP.NET Web Form Designer. // InitializeComponent (); base.onit (e);} /// Private void Lall_Click (Object Sender, System.Eventargs E) {while (listbox2.items.count! = 0) {listbox1.items.add (new ListItem (ListBox2.Items [0] .Value); listbox2.items.remove (ListBox2.Items [0] .value); } Private void querydetails (arraylist marr, string tablename) {straconn = getAdbconfig (); strcmd = "select"; for (int i = 0; i private void Button2_Click (object sender, System.EventArgs e) {if - {int tmpIndex = ListBox1.SelectedIndex (ListBox1.SelectedIndex = 1!); string tmpText = ListBox1.Items [tmpIndex] .Text; string tmpValue = ListBox1.Items [ Tmpindex] .value; ListItem Li = new ListItem (); li.text = tmpText; li.value = tmpValue; listbox1.items.remove (listbox1.items [tmpinDex]); listbox2.items.add (li);}} private void Button3_Click (object sender, System.EventArgs e) {if - {int tmpIndex = ListBox2.SelectedIndex (ListBox2.SelectedIndex = 1!); ListItem li = new ListItem (); li.Text = ListBox2.Items [tmpIndex]. Text; li.value = listbox2.items [tmpinDex] .value; listbox2.items.remove (listbox2.items [tmpinDex]); listbox1.items.add (li);}}