Solved

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

Posted on 2009-07-14
13
325 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
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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

914 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

14 Experts available now in Live!

Get 1:1 Help Now