How to dynamic bind Listbox DataSource?
-
I want to change my ListBox DataSource by a button event,but Where page reload ,The listbox is empty,How to do?
-
I want to change my ListBox DataSource by a button event,but Where page reload ,The listbox is empty,How to do?
you should change property "AutoPostBack=Ture" in the listbox properties. try it i think it helpful.
-
you should change property "AutoPostBack=Ture" in the listbox properties. try it i think it helpful.
I test your tips, it still does not work,my code is here.
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Data.OleDb; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using WinPbMove; namespace WebPbMove { /// /// public class WebProdSelect : MetaBuilders.WebControls.DialogPage { protected System.Web.UI.WebControls.TextBox TextBox1; protected System.Web.UI.WebControls.Label Label1; protected System.Web.UI.WebControls.ListBox ListBox1; protected System.Web.UI.WebControls.Button cmdFilter; protected System.Web.UI.WebControls.Button cmdReturn; private PbMove dl = null; const string MYSTRING = "-------"; private void Page_Load(object sender, System.EventArgs e) { string strSQL = ""; if (!Page.IsPostBack) { if (dl == null) dl = new PbMove(); if (dl.OpenConnection() == false) throw(new SystemException("Connect Oracle Failed!")); OleDbConnection cn = dl.Connection; if (TextBox1.Text == "") { strSQL = "Select t.prdct_name || '" + MYSTRING + "' || t.dscr From ip_prdct t"; } else { //TextBox1.Text = Session["UserFilterString"].ToString(); strSQL = "Select t.prdct_name || '" + MYSTRING + "' || t.dscr From ip_prdct t" + " Where t.dscr like '%" + TextBox1.Text + "%'"; } OleDbDataAdapter adpter = new OleDbDataAdapter(strSQL,cn); DataSet ds = new DataSet(); adpter.Fill(ds,"IP_PRDCT"); DataTable dtProdct = ds.Tables["IP_PRDCT"]; ListBox1.DataSource = dtProdct; ListBox1.DataTextField = dtProdct.Columns[0].ColumnName; ListBox1.DataValueField = dtProdct.Columns[0].ColumnName; ListBox1.DataBind(); } } #region Web override protected void OnInit(EventArgs e) { // // InitializeComponent(); base.OnInit(e); } /// /// private void InitializeComponent() { this.cmdFilter.Click += new System.EventHandler(this.cmdFilter_Click); this.cmdReturn.Click += new System.EventHandler(this.cmdReturn_Click); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void cmdFilter_Click(object sender, System.EventArgs e) { if (dl == null) dl = new PbMove(); if (dl.OpenConnection() == false) throw(new SystemException("Connect Oracle F