locked
ObjectDS, Listview, Parent/Child, Datakeys, DAL, BLL, etc... RRS feed

  • Question

  • User-1275158598 posted

    I've been working on trying to get a parent/child relationship working between two listviews using an ObjectDataSource.  The data is represented in a class librabry called the DAL (Data Access Layer) and the business rules in another class library called the BLL (Business Logic Layer).  I used a tutorial here on ASP.net to begin my journey.  They used a website instead of a web project though.  I wanted a project for various reasons.

    It took me over two weeks to get the kink worked out and thought I would post some of my problems along with their solutions.

    • The DAL with typed dataset shows a set or parameters that you use in the BLL to pass along values.  However, when you run the page it list's more parameters than what's listed in the DAL.  I believe this was because of my parent/child relationship.  I changed my BLL methods to include these added parameters from the error page and that solved the error, but was unable to update and delete data.  I debugged the method and found that my child table primary key was not being passed in as the Original_ID.
    • This was because I had set the child table DataKeys to the parents key.  It finally dawned on me that you could have a comma separated list of DataKeys and once I included both keys the updates and deletes worked.
    • It also took me awhile to learn how to use the ODS inserting, updating, selecting events to set parameter values.  Just use the e.InputParameters['name"] = value to set them.  I was selecting values from the database depending on the user logged on so i was able to set the username parameter this way.
    • I'm sure I have forgot many of the problems I encountered.  I was dead set on using the ListView control because I liked the way it looks.  The only downfall I see is that you can't set a CSS class.  Oh, in order to setup the templates auto, just drop a SQLDataSource on page and set the ListView to the datasource and then hit configure ListView and select all the checkboxes and it auto generates all the templates for you.  You can then delete the ones you don't want.  You do this because the ODS will not set it up like this.  Then you just set the ListView back to the ODS.

    Here is a picture of what the page turned out to look like.  Yes, the export to Excel works great.  I think the ListView contro, DAL and BLL classes, and ODS are the way to go.  If you have any questions please feel free to ask away.

    Paul

    Tuesday, February 14, 2012 9:06 PM

Answers

  • User-1275158598 posted

    Thanks Decker Dong-MSFT.  I've figured out how to read values from the different templates of the ListView.  If you just use the normal findcontrol I think it defaults to the items template.  Here is some code to get the values from the insert template of the ListView.

    TextBox journalName = (TextBox)lvJournal.InsertItem.FindControl("journalNameTextBox");

     I'm now using code like this to add in my error checking before inserting into the database.  Just using a label to display an error message under the item being edited or inserted and setting it's .visible to true or false depending on if it has errors or not.

    I should be done with this page after the error handling is done.  I've learned a lot of things these past two weeks.  I'm retired now, but I started out using C as a teenager, then took C++ in college along with COBOL and FORTRAN.  My first real programming job after I left the Navy was using Borland's Delpi.  Then on to PowerBuilder.   Things have changed a lot since then, and I like this ASP.Net programming.  Sure makes programming easier than it used to be that's for sure.  You take care.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 17, 2012 11:25 AM

All replies

  • User3866881 posted

    Many thanks for sharing such a nice solution for us!Congratulations!

    Thursday, February 16, 2012 8:14 PM
  • User-1275158598 posted

    Thanks Decker Dong-MSFT.  I've figured out how to read values from the different templates of the ListView.  If you just use the normal findcontrol I think it defaults to the items template.  Here is some code to get the values from the insert template of the ListView.

    TextBox journalName = (TextBox)lvJournal.InsertItem.FindControl("journalNameTextBox");

     I'm now using code like this to add in my error checking before inserting into the database.  Just using a label to display an error message under the item being edited or inserted and setting it's .visible to true or false depending on if it has errors or not.

    I should be done with this page after the error handling is done.  I've learned a lot of things these past two weeks.  I'm retired now, but I started out using C as a teenager, then took C++ in college along with COBOL and FORTRAN.  My first real programming job after I left the Navy was using Borland's Delpi.  Then on to PowerBuilder.   Things have changed a lot since then, and I like this ASP.Net programming.  Sure makes programming easier than it used to be that's for sure.  You take care.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 17, 2012 11:25 AM