 |
| ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

April 15th, 2010, 07:02 AM
|
|
Registered User
|
|
Join Date: Mar 2010
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
My ItemDataBound event doesn't seem to fire? Do I have my query within the wrong event?
Thanks.
|
|

April 15th, 2010, 10:25 AM
|
|
Registered User
|
|
Join Date: Mar 2010
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Did you receive my last posts? I think the web site was down for a while.
Thanks.
|
|

April 15th, 2010, 04:50 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Take a look at this:
Traders myTraders = dataItem.DataItem as Traders;
Your DataItem is probably not a Traders instance. As such, the conversion fails, and myTraders remains null. This in turn means the control is never bound.
What do you see when you debug? That would be the way to figure these thing out. Because of the database dependency, I can't help much, other than tell you where to look for potential problems.
Cheers,
Imar
|
|

April 16th, 2010, 04:51 AM
|
|
Registered User
|
|
Join Date: Mar 2010
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
That's my whole problem - I can't debug my ItemDataBound event as the error is occuring within my OnSelecting event, i.e. before my ItemDataBound event is fired. Can you think of any reason why your control would act this way bound to a linqdatasource instead of an objectdatasource? Thanks.
|
|

April 16th, 2010, 05:15 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
You could try calling DataBind on your List or DataSource control manually in an earlier event, like Page_Load. Apparently when the control starts binding the life cycle is in Databinding mode and then my control does its checks.
Alternatively, you could remove the check in the control and not throw an error.
Again, since I don't have a reproducible scenario, I cannot test this for you. I also don't have the time to build a sample project and try to reproduce this for you. So, unless you send me a complete sample project, there's not much I can do for you.
Cheers,
Imar
|
|

April 16th, 2010, 06:03 AM
|
|
Registered User
|
|
Join Date: Mar 2010
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
How would I remove the check in your control and not throw the error?
Thanks again.
|
|

April 16th, 2010, 06:21 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
What about deleting the lines that do the check and throw the exception?
Not trying to be funny, but if you look at the code, it should be easy to see where this check is made and the error is thrown....
Imar
|
|

April 19th, 2010, 05:56 AM
|
|
Registered User
|
|
Join Date: Mar 2010
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Imar,
I managed to delete the lines in your control that do the check and throw the exception but as predicted this led to other issues, i.e. within your RattingSettings class your rateItems variable is now null, which will be due to the fact that the ItemId cannot be found from the data source. Basically I cannot figure out a way to provide your control within my listview with an ItemId before I bind my listview, i.e. ContentRating1.DataSource must be bound before my listview has been bound but ContentRating1 requires the rating values returned from my listview's bound query - it's a bit of a catch 22!
Thanks.
|
|

April 20th, 2010, 05:09 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Like I said, I can't help you if you don't give me a reproducible and representable scenario. The C# example using classes was reproducible, but not representable.
I am sure this is all relatively easy to fix; it shouldn't take weeks. However, since I don't know what the problem is I can't fix it.
If you can, zip a fully working example (with just the files and tables needed) using your database schema, data, etc and either mail it to me or provide a download link somewhere. Then next week I'll be able to take look (on vacation now).
As I suggested earlier, did you try explicit binding in Page_Load? What happended when you try that?
Cheers,
Imar
|
|

April 20th, 2010, 06:57 AM
|
|
Registered User
|
|
Join Date: Mar 2010
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Imar,
Sorry I interrupted your vacation!
Unfortunately, I am already calling my Bind methods from my page load event.
If you find the time please navigate to the below address where you can download my ListView_Rating.zip file which holds my test web site. Simply extract and open the web site through VS 2008. You will have to have sql server 2008 express installed for it to work....
http://www.tradeselector.co.uk/Misc/ListView_Rating.zip
Thanks again.
|
|
 |