Solved

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

Posted on 2009-07-14
13
326 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 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