Groups | Blog | Home
all groups > visual studio .net general > january 2006 >

visual studio .net general : Connecting ObjectDataSource to FormView control


Mal Ball
1/26/2006 3:58:03 AM
I have a business object class created in my App_Code folder which gets
customer data from a SQL Server database in its Select method. The select
method returns a dataset.

I have a FormView on my aspx page which should display this data but I
cannot get any data to display, it always shows the No Data page.

I have set the DataSourceID to that of the ObjectDataSource, and I call the
select method in my Page_Load event, is there anything else I need to do?
--
Mal Ball
1/27/2006 1:11:35 AM
If I have the following settings in my load event I get a record listed in
the formview:

FormView1.DataSource = dsCustomer;
FormView1.DataSourceID = "";

However, the DataSourceID must be set in the properties in design mode to
CustomerDataSource for this to work, if I remove this it does not work.

If I set the FormView1.DataSourceID in the load event to CustomerDataSource
I get a runtime error saying that I cannot have both properties filled.

Sorry I am not sure what you mean about giving you a repro step.

--
Mal Ball


[quoted text, click to view]
v-kevy NO[at]SPAM online.microsoft.com
1/27/2006 2:40:33 AM
Hi,

Are you binding the FormView to a class object or to the DataSet? If you're
binding to the DataSet, is there anything in the data source?

If possible, could you give me a repro step, so that I can try to debug it
on my machine? Thanks!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
v-kevy NO[at]SPAM online.microsoft.com
1/31/2006 12:00:00 AM
Hi Mal,

The page remains to be empty, because the item templates of FormView is not
set. To set it fast, you can

1. Set the DataSourceID to certain datasource like dsCustomer at design
time.
2. Clear the DataSourceID field in the properties window.
3. A dialog box will pop up to ask you if you need to clear the templates.
Click No.

Then you can specify DataSourceID at runtime in code. And the data will be
displayed properly. Also make sure to set either DataSource or
DataSourceID. Just don't set both of them.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
Mal Ball
1/31/2006 10:17:27 AM
Ok, I have reset the properties at design time as follows:
DataSourceID = blank
DataMember = blank
DataKeyNames = customerID

At run time in my page load event I have:
dsCustomer = CurrentCustomer.Select(SelectedCustomer);
CustomerDataSource.DataBind();
this.FormView1.DataSourceID = "CustomerDataSource";
or
this.FormView1.DataSource = dsCustomer;

Neither provide data in the form view.

--
Mal Ball


[quoted text, click to view]
v-kevy NO[at]SPAM online.microsoft.com
2/1/2006 12:00:00 AM
Hi Mal,

In the design mode of the page, can you see the FormView with all fields in
it? Or just a big grey box?

If not, you can check the following links for more information about
applying templates to the control.

http://msdn2.microsoft.com/en-us/library/ms227423.aspx
http://msdn2.microsoft.com/en-us/library/ms228089.aspx

Also, this link will be helpful.

http://msdn2.microsoft.com/en-us/library/fyf1dk77.aspx

The template should be applied first, or the FormView control will not know
how to display the data.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
Mal Ball
2/1/2006 1:23:28 AM
Thanks for the help and the links, I will experiment further.
--
Mal Ball


[quoted text, click to view]
v-kevy NO[at]SPAM online.microsoft.com
2/2/2006 4:19:47 AM
You're welcome, Mal.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
AddThis Social Bookmark Button