views:

164

answers:

3

here is a class code :

> [DataObjectAttribute] public class
> Report {    public this() {}
> 
>  
> [DataObjectMethodAttribute(DataObjectMethodType.Select,
> true)]   public static
> GetAllEmployees() : DataTable   {
>       null   }
> 
>  
> [DataObjectMethodAttribute(DataObjectMethodType.Delete,
> true)]   public
> DeleteEmployeeByID(employeeID : int) :
> void   {
>        throw Exception("The value passed to the delete method is " +
> employeeID.ToString());   } }

but I still can't find where and how and what I must to config to access it ?

  <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod=" ?????????? ">
  </asp:ObjectDataSource>

Web Application doesn't support App_Code so but I can use compiled Bin somehow, the question is how ?

text from this link only confused me more :(

thank you

+1  A: 

for class use [DataObject] attribute. this should help you.

in tag refer class using TypeName.

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod=" ?????????? " TypeName="class with complete namespace">
  </asp:ObjectDataSource>
Saar
You don't need to set the [DataObject] attribute to use a select method in an ODS. It's only required to use the DataObjectMethodAttributes on the method.
citronas
@citronas: good to know. will give try.
Saar
try to make it manually ? so wizard can't see my classes
nCdy
there must be some reference somewhere !
nCdy
+1  A: 

Clarify your question please.

It is possible to use an ObjectDataSource from Select/Delete/etc. methods out of a dll.

Try to use the wizard of the ObjectDataSource to set the context property of the ODS.

citronas
wizard can't see this class - that's a problem
nCdy
Clean and Rebuild your Solution. Even try a restart. Make sure you don't have checked the checkbox in the wizard, that says you only want DataContextObjects to be displayed
citronas
I can see a big big big message "BE SURE THAT YOUR CLASS IS IN APP_CODE or Referenced" it is not , how must I reference it ? :S
nCdy
??? In your question you said that you'd be using a web application and not a web site project.
citronas
yes ... I'm using Web Application.
nCdy
Ah. Right click on your project and click "Add Reference". Then switch to the tab where you can select a file. Select the dll where your select method is located.
citronas
+1  A: 

You can work in work in source mode to configure the ObjectDataSource by I find it easier to use the smart tag from the control in design mode. If your data access dll is part of the project then you will be able to select it from the Choose A Business Object page of the Configure Data Source wizard(1st screen of the wizard). If your data access dll in in another project, you will need to add a reference to it.

EDIT:

Here is some of my working sample code to give you an idea as to what things should look like.

Data access layer:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel;
using Model;

namespace DAL
{
    [DataObject(true)]
    public class DepartmentDAL
    {
        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public IEnumerable<Model.Department> GetDepartments()
        {
            using(KDMEntities ctx = new KDMEntities())
            {
                return ctx.Departments.OrderBy(n => n.DepartmentName).ToList();
            }
        }

        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public Department GetDepartmentByID(int deptID)
        {
            using (KDMEntities ctx = new KDMEntities())
            {
                  // More similar code...

ASP.NET markup:

<asp:ObjectDataSource ID="odsDepartments" runat="server" 
    OldValuesParameterFormatString="original_{0}" SelectMethod="GetDepartments" 
    TypeName="DAL.DepartmentDAL">
</asp:ObjectDataSource>


            <asp:GridView ID="gvDepartments" runat="server" DataSourceID="odsDepartments" 
                CssClass="datagrid" EnableViewState="true" AutoGenerateColumns="False" ShowFooter="true" Width="200px">
                <Columns>
                    <asp:BoundField DataField="DepartmentName" HeaderText="Department"/>

<!-- Other columns -->

                </Columns>
            </asp:GridView>

Here's how the ObjectDataSource markup would look when using a custom type:

    <asp:ObjectDataSource ID="odsDeptDetail" runat="server" 
        DataObjectTypeName="DAL.Department" InsertMethod="AddDepartment" 
        OldValuesParameterFormatString="original_{0}" SelectMethod="GetDepartmentByID" 
        TypeName="DAL.DepartmentDAL" UpdateMethod="UpdateDepartment" >
        <SelectParameters>
            <asp:QueryStringParameter DefaultValue="0" Name="deptID" QueryStringField="did" Type="Int32" />
        </SelectParameters>
    </asp:ObjectDataSource>

Department is my custom type, just a simple DTO really.

Since you are working with a web application, all you C# code will be compiled into a DLL located in the bin directory. When you deploy your code to a production server, all you need to do is copy the *.aspx files and the contents of your bin folder. This is a slight oversimplification as there could be other files to copy. Refer back the document you have on deploying web applications.

DaveB
I've tried both ... doesn't helps :-/
nCdy
I added some sample code and comments.
DaveB
thank you for description. got some qustions : 1) what is using Model; (didn't found it) ??? 2) So ObjectDataSource must see this TypeName ? So I guess I'm making something wrong because wizard can't see it. Can your wizard see this class ? why my can't see classes :-/
nCdy
How to deploy project as different dlls ?
nCdy
Finally .... all problems are fixed ... I love stackoverflow <3
nCdy