Last post Aug 12, 2011 07:57 AM by ShearWater509
Aug 08, 2011 11:31 AM|ShearWater509|LINK
I will be honest with you - I have taken exactly 1 ASP.NET class (instructional class...not object class, haha), so I might be doing this all wrong. I am developing an online employment application for the company that I work for. In my ASP.NET class, they
taught us to try and avoid having our .aspx pages speak directly to the database (which I had always done before), so I am trying my best to use that best practice, but this is my first time doing it like this, and there's still some issues I'm trying to work
out. I started building this application like I used to build all my other applications...but I think I need help from some more seasoned professionals on how to streamline what I've done in the past to make it fit what I'm trying to do now.
The way I organize my data is like this:
So, now that you understand how my application structure is organized (or messed up, depending on how you look at it - and I am welcome to suggestions on how to improve this), here is where my problem with the ObjectDataSource is:
I have a user control called RelativeSupervisorsRecordView.ascx, which has fields for last name, first name, middle name, and relationship. This is where applicants will enter in any supervisors at our company who are related to them, and how. The user can
click an add button to get as many or few of these user controls as they want, in case they have anywhere from zero to a zillion relatives that are supervisors at my company.
The Relationship part of this user control is the issue. The relationship is a database table with ids 1 through 8, and values like Parent, Cousin, Child, Granparent, etc.
My user control connects to my Master page and calls the loadRelationshipTypes() method inside of my ObjectMethods class. That method, in turn, calls loadRelationshipTypes() in my DataMethods.cs class, which populates my Relationships data table. Then, the
ObjectMethods class takes that data, creates 8 relationship objects out of it, and returns the objects in an IList<RelationshipTypes> to my user control. Then, in the Page_Load method, my user control binds that IList to the DropDownList inside itself. When
I watch this happen in debug mode, stepping through the code, everything looks good. The data is coming from the database ok, the objects are being created okay, I'm not seeing any exceptions generated on the DataBind command after I set the datasource property
of the dropdownlist control, and all looks well. Then, when the page displays, my drop down list has nothing in it. What gives?
If code would make it easier, let me know and I'll post it.
Aug 12, 2011 05:10 AM|Decker Dong - MSFT|LINK
ObjectDataSource appears to databind to DropDownList correctly, but no data displays.
Plz show us your codes....
I wonder whether you've set DataTextField or DataValueField for the Dropdownlist... And plz don't forget to call DataBind().
Aug 12, 2011 07:57 AM|ShearWater509|LINK
I'm a loser. I figured it out.
On the page source, I had the drop down list markup like so:
<asp:DropDownList ID="RelativeSupervisorsDropDownList" runat="server" \>
And then in the code-behind in the Page_Load method, I had this:
DropDownList RelativeSupervisorsDropDownList = new DropDownList()
RelativeSupervisorsDropDownList.DataSource = myObject()
Or something similar to that...
But the key was that first line - I was making a new drop down list object and data binding to it, but never adding THAT instance of the drop down list to the page. Once I got that "new" line out of there, it worked just fine.
Thank you though!