Solved

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

Posted on 2009-07-14
13
329 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 3
13 Comments
 
LVL 15

Assisted Solution

by:jinal
jinal earned 200 total points
ID: 24850031
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
ID: 24850076
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
ID: 24850118
>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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

Author Comment

by:Nyana22
ID: 24850129
didn't work
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24850133
>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
ID: 24850143
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
 
LVL 15

Expert Comment

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

Author Comment

by:Nyana22
ID: 24850344
warID
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24850423
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
ID: 24850456
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
ID: 24850478
LB1.DataSource = FCT1()
LB1.DataTextField = "WarID"
LB1.DataValueField = "WarID"
LB1.DataBind()
0
 

Author Comment

by:Nyana22
ID: 24850753
thanks
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24850767
Is it working?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

695 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