Solved

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

Posted on 2009-07-14
13
322 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:Nyana22
  • 5
  • 5
  • 3
13 Comments
 
LVL 15

Assisted Solution

by:jinal
jinal earned 200 total points
Comment Utility
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
 

Author Comment

by:Nyana22
Comment Utility
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
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
>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
 

Author Comment

by:Nyana22
Comment Utility
didn't work
0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
>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
 
LVL 15

Expert Comment

by:jinal
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 15

Expert Comment

by:jinal
Comment Utility
Can you please give me column name that return from objectdatasource.
0
 

Author Comment

by:Nyana22
Comment Utility
warID
0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
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
 

Author Comment

by:Nyana22
Comment Utility
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
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 300 total points
Comment Utility
LB1.DataSource = FCT1()
LB1.DataTextField = "WarID"
LB1.DataValueField = "WarID"
LB1.DataBind()
0
 

Author Comment

by:Nyana22
Comment Utility
thanks
0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
Is it working?
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now