Forum guidelines
  • Home
  • »
  • C# Language
  • »
  • how to fetch data sql to listbox on textbox change event
AuthorQuestion
how to fetch data sql to listbox on textbox change event
Posted on: 02 May 2013
hi.
i m trying to fetch data sql server to listbox on textbox change event but i m getting only system.Row.RowView now to do it....... as listbox item willn be as enter in textbox.......

AuthorReply
Re: how to fetch data sql to listbox on textbox change event
Posted on: 08 May 2013  
You need to use a foreach to loop through whats coming back from the SQL and add to your listbox.

As an example (using entity framework)

                YourEntities myentities = new YourEntities ();
                ObjectResult<ComplexTypeFromEF_Result> Result = myentities.FunctionFromEF(//passed parameters for combo box population);

                foreach (var item in Result)
                {
                    ListBOx1.Items.Add(new ListItem(item.item1.ToString(), item.itemID.ToString()));

                }

Re: how to fetch data sql to listbox on textbox change event
Posted on: 08 May 2013  
hi,

which technology are you using as a data access?
ok
are you assigning direct data source to List box or adding one by one row?

if you has array list or List of string than you can assign it as a datasource.

ArrayList s = GetListData();

listBox1.Items.Clear();
listBox1.DataSource = s;

if your data source is other than arrayList or List of string than you can use DisplayMember property of List Box

DataTable s = GetListData();

listBox1.Items.Clear();
listBox1.DataSource = s;

listBox1.DisplayMember = "Name";

hope this will help you.





SPONSORED BY

Offshore Software and Database Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.