[C# 2.0] class library (DAL), GridView, ObjectDataSource, XML File path.....

asp.net Tunisia
  • 14 years ago

    hi all ! it's my first post here, so let me welcome myself :)))
    ok let me expalin the problem i did a class library project where i have some classes between those i have a DAL class  that will permit to process datainto an xml file. then i did an asp.net project i insert a gridview in a page and configured a dataObjectSource for that gridview all it's ok here .
    the problem is that my DAL's class (which is the DataObjectSource here) constructor takes the xmlfile path as a parameter, but, the gridview needs a constructor without parameters so how can i let my xml file path parameterisable in my DAL ? in other termes if i'm obliged to have a contructor with no parameters how can i  pass  the xml file path to that class ( when the gridview instancies the class) ?
    ps: sorry for my english :)
    thks in advance





  • 14 years ago

    It wud be really helpful if you give the signatures of your methods in different layers. So that would make things a bit more clearer. Smiley Face [:)]

  • 14 years ago

    i thought i was clear :)
    my ObjectDataSource for the grid is a class named MyDAL, it has a constructor like that :
    public MyDAL(string XmlFilePath)
    {
        this._XmlPath = XmlFilePath; //
    }
    so this class is in a library class project named project A.
    now i have a project B referencing project A
    project B is an asp.net web site in that project i have : default.aspx and in that page i have these controls:
    gridview1 : the ObjectDataSource is objectdatasouce1
    objectdatasouce1 : the business object is MyDAL

    now when i launch the project B there is an error because the gridview needs a constructor with no parameters for MyDAL...so, if i put my xmlfilepath in hard coded mode in my class MyDAL and modify then the contructor to make it with no parameter then all works well.
    the problem is that : i want to make the XmlFilePath a parameter for MyDAL class, how can i do this ? 












  • 14 years ago
    finally i found the solution :) so for those interested take a look at :
    http://msdn2.microsoft.com/en-US/library/system.web.ui.webcontrols.objectdatasource.objectcreating.aspx

    have a nice coding !




  • 14 years ago

    Hi Mourad,

    So as per your solution, you are using the ObjectDataSource' ObjectCreating event to accomplish your work. And if I'm guessing right you have used two different constructors in your MyDAL like

    public MyDAL() { .... } // as the default constructor

    public MyDAL(string xmlPath) { .... } // as the secondary constructor

    But how do you make this xmlPath the parameter and supply the path when using it with the objectDataSource?

     

     

  • 14 years ago

    hi inferano,
    you should take a look at the link i posted ;)
    ok i'll explain briefly in the "ObjectDataSource_ObjectCreating" event i can make an instance of MyDAL and affect it to the "ObjectInstance" property of the ObjectDataSource and then it's that instance of MyDAL that will be used in that case and so i can have any constructor in MyDAL with no problem.... ;)



Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Most software today is very much like an Egyptian pyramid with millions of bricks piled on top of each other, with no structural integrity, but just done by brute force and thousands of slaves” - Alan Kay