Click here to Skip to main content
15,887,911 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hallo everyone,

What is the equivalent of BindSource Datasource object in Asp.Net application?

Thanks
Posted
Comments
strogg 14-Jun-11 11:51am    
BindSource? there's no thing such as a BindSource, tell me what exactly you want to do & i'll let you know
Yonathan1111 16-Jun-11 2:35am    
I first say sorry for my delayed response.
I have been working on ReportViewer control, the example I found uses BindSource object found in the Data section of Toolbox. By the way it is a windows application.
You may see it and say something on. Here is the source link http://aspalliance.com/762. What I wished is, I want to adabt the idea into Asp.Net application, however, I couldn't find this object.

Thanks a lot,
strogg 16-Jun-11 16:09pm    
It depends on the kind of data you wish to bind to the report viewer. You can use the SqlDataSource if you want to bind data from an sql server database. You can also set your own DataTable to the report as the datasource. If you'll be more clear as to what kind of data you have to use with the reports, i can specifically tell you how to do it.
Yonathan1111 17-Jun-11 2:47am    
Ok,
I will try to be more clear. The system I am developing gets its data at runtime, which means I feed it up dynamically (programmatically), I have to use a Dataset.
Thanks

To manually bind a DataTable to a report viewer

Remove any designer data bindings you have on the report viewer control
(make sure there's nothing in the <DataSources> element as shown below)

XML
<LocalReport ReportPath="Report.rdlc">
  <DataSources>
  </DataSources>
</LocalReport>


Add a new dummy DataSet in your App_Code folder (or make use of one if you have). Place a table in the designer and add the same columns you have in your datatable you wish to use (I'll assume the name of the DataSet is DataSet1 & that of DataTable is DataTable1)

Once you have your DataSet ready, you may add a table or other object in your report designer & drag fields from the DataSet onto it.

Here's how you bind your data in DataTable (or DataSet) to the report - in a event or Page_Load
Assuming you have a loaded DataTable named dt
ReportDataSource rds = new ReportDataSource("DataSet1_DataTable1", dt);
ReportViewer1.LocalReport.DataSources.Add(rds);
ReportViewer1.DataBind();


Remember to import namespace Microsoft.Reporting.WebForms for it

I have a little demo page showing how to do it - if you need it, ask me. I'll send it.
 
Share this answer
 
Comments
Yonathan1111 20-Jun-11 6:36am    
Here it is how I tried,
DataSet1 ds = new DataSet1();
DataTable dt = new DataTable("DataTable1");

dt.Columns.Add("firstname");
dt.Columns.Add("lasttname");

DataRow dr = ds.Tables[0].NewRow();

dr["firstname"] = "Reportviewer";
dr["lastname"] = "Microsoft";

dt.Rows.Add(dr);
ds.Tables.Add(dt);

ReportDataSource rds = new ReportDataSource("DataSet1_DataTable1", dt);
ReportViewer1.LocalReport.DataSources.Add(rds);
ReportViewer1.DataBind();

I just created a DataSet called DataSet1 and a Table called DataTable1 as you said.

I think you better send me your demo.

Thanks
strogg 20-Jun-11 9:02am    
You've done right, but you had to create the DataSet in the designer. Anyway you can download the files here - http://www.yourfilelink.com/get.php?fid=697834
Choose open website & open the folder
Yonathan1111 29-Jun-11 4:39am    
Hi strogg,
Thank you for your advanced help. I didn't get time to reply you immediatly a soon as I see your message. I could't download it, anyway I thank you very much.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900