GridView - ObjectDataSource NOT retrieving records

  • Thread starter Thread starter Randy Smith
  • Start date Start date
R

Randy Smith

Hi ALL,
I wonder if anyone has been using n-tier to bind to a GridView control by
using the ObjectDataSource. This is our first OOP web application, and we
have no tables. Right now we are simply working with objects in memory.

So, it appears as though Microsoft requires that our datamapper classes
reside inside a folder called "App_Code", and NO WHERE ELSE.

So, has anyone successfully been able to place their datamappers in a
location other than "App_Code", and actually retrieve records from a
datamapper class?

TIA, Randy
 
Hi Phillip,
I rally appreciate your help. I like your sample "Dropdownlist within a
GridView", but I do have a few questions about your ObjectDataSource.

Here is the code I'm interested in:
<asp:ObjectDataSource ID="odsProducts" runat="server"
SelectMethod="ProductByID"
TypeName="WEBSWAPP_BLL.Demos"
DataObjectTypeName="WEBSWAPP_BLL.clsProduct">
<SelectParameters>
<asp:ControlParameter
ControlID="ddlProducts" Name="productID" PropertyName="SelectedValue"
Type="String" />
</SelectParameters>
</asp:ObjectDataSource>


1) I presume that "WEBSWAPP_BLL" is a DLL, right? Where is it located in
your folder structure?
2) I see that you are using "TypeName". I presume that "Demos" is the class
inside your "WEBSWAPP_BLL" DLL, right?
3) Did you have to add any specific entries into the web.config file to get
it to work?
4) I haven't seen your "default.aspx.cs" code, but do you have this
reference: "using WEBSWAPP_BLL;" (C#)?

Many thanks, Randy
 
Hi,
Well, I've changed my ObjectDataSource to match your examples, but I am
still not getting any data. I wonder if you can post the code for
"default.aspx.cs" (within "Dropdownlist within a GridView". I'm
particularly interested in seeing how you go about doing the "databind",
which may be my problem.
Many, many thanks!!! Randy
 
Have you tried stepping in debug mode with break points within the BLL & DAL
to see if the web interface is calling the methods of your object library?
It might be an issue of the structure of your namespaces. In my demos I put
the fully qualified name of the class starting from the root namespace, e.g.
WEBSWAPP_BLL.Demos is the fully qualified path.

In your case it might be something like MyCompany.Modules.App1.className.
Make sure you put the fully qualified path in the values for TypeName and
DataObjectTypeName properties of the ObjectDataSource. Then set break points
within those methods to debug in VS.
 
So,
Do I understand that you didn't need to do any sort of "databind"? I had
this code in my Page_Load event:
gvMaterialRates.DataSource = ObjectDataSource1;

gvMaterialRates.DataBind();

I've tried it several different ways:
1) As above
2) With the "DataSource" line commented out, and the other line active.
3) With the "DataBind" line commented out, and the other line active.
4) With both lines commented out.

I'll try the debug route and see what happens.

Randy
 
UPDATE:
I debugged the "FetchAllRates" and found that it was showing a count of ZERO
records, even though I have 3 rows in the object. It then dawned on me that
our consultant switched us over to ApplicationManager.cs. This piece of
code actually returns a count of 3, whereas my direct code retrieves ZERO.
lblRows.Text =
ApplicationManager.MaterialRateDM.FetchAllRates().Count.ToString();
//returns 3 rows



Here's the code I was using for my ObjectDataSource:

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"

SelectMethod="FetchAllRates" TypeName="GWO.MaterialRateDataMapper"
EnablePaging="false">

</asp:ObjectDataSource>

If I replace the "GWO.MaterialRateDataMapper" with
"ApplicationManager.MaterialRateDM", I get an error indicating that
"FetchAllRates" could not be found.
 
Back
Top