bind a list box to an object data source in ASP.NET

Hello,
How can i bind a list box to an object data source
in a button click event.
i wrote :
listbox1.datasourceID = "objectdatasource1"
listbox1.databind

and i got in the list box rows having System.Data.DataRowView.
thanks
i am using VB
Nyana22Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jinalCommented:
As i seen that you are binding datatable or DataView to listbox1.

So please set DataTextField and DataValueField . This is the name of DataTable Column.

listbox1.datasourceID = "objectdatasource1"
listbox1.DataTextField = ""   // Please provide this information
listbox1.DataValueField =""   // Please provide this information.
listbox1.databind()

Open in new window

0
Nyana22Author Commented:
ah yeah, the OS is bound to a function in the DAL, that returns a DataSet.
but why i need to do so, if i want to bind a datatable or...
thanks
0
CodeCruiserCommented:
>As i seen that you are binding datatable or DataView to listbox1.

The question title and the id of the datasource explicitely says its an OBJECTDATASOURCE not a datatable or dataview. But yes set the DataTextField and DataValueField properties appropriately.
0
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Nyana22Author Commented:
didn't work
0
CodeCruiserCommented:
>ah yeah, the OS is bound to a function in the DAL, that returns a DataSet.
Why not bind the dataset directly to list then?
0
jinalCommented:
If you manually create listitem then its ok.

Like
listboxl.Items.Add(new ListItem("text1","value"));

But here you bind datatable or dataset that's why you have to provide that information.
0
jinalCommented:
Can you please give me column name that return from objectdatasource.
0
Nyana22Author Commented:
warID
0
CodeCruiserCommented:
I repeat my question:
If DAL is returing you a dataset, you could bind to this dataset directly without using an objectdatasource in between. Is there any reason for not taking this approach?
0
Nyana22Author Commented:
no, i just didn't understand!!
i am new to this,
can u please tell me how in vb code,
if the function returning a dataset is called FCT1. and the list box is LB1
thanks
0
CodeCruiserCommented:
LB1.DataSource = FCT1()
LB1.DataTextField = "WarID"
LB1.DataValueField = "WarID"
LB1.DataBind()
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Nyana22Author Commented:
thanks
0
CodeCruiserCommented:
Is it working?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.