Select the table field using the ListBox control

xiaoxiao2021-03-06  14

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 ----------------------------- .................

< ASP: Button ID = "Button2" Style = "Z-Index: 110; Left: 328px; Position: Absolute; Top: 136px" Runat = "Server" text = "button"> ................

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);} ///

/// Designer Supports the required method - Do not use the code editor to modify the // / this method. /// private void InitializeComponent () {this.Button1.Click = new System.EventHandler (this.Button1_Click); this.LAll.Click = new System.EventHandler (this.LAll_Click); this.RAll .Click = new System.EventHandler (this.RAll_Click); this.Button2.Click = new System.EventHandler (this.Button2_Click); this.Button3.Click = new System.EventHandler (this.Button3_Click); this. Load = new System.EventHandler (this.Page_Load);} #endregion private void RAll_Click (object sender, System.EventArgs e) {while (! ListBox1.Items.Count = 0) {ListBox2.Items.Add (new ListItem ( Listbox1.items [0] .value); listbox1.items.remove (ListBox1.Items [0] .value);}}

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);}}

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

New Post(0)