Can I force an asp.net listviews ItemDataBound event to fire?

Hi,

I am populating an asp.net listview control from my page_load event. Unfortunately, due to my projects requirements, I have to use a third party control within my listviews ItemTemplate that needs to have database values written to its attributes before my listview control is bound, if this is not the case my control flags a null reference exception error. From some investigation into the listview control, it seems that the only way to do this is through my listviews ItemDataBound event as my thrid party control will hold different value depending on each row.

I was wondering if it's at all possible to force my listviews ItemDataBound event to fire before I call mylistview.databind();?
aspnet-scotlandAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

masterpassCommented:
if it's at all possible to force my listviews ItemDataBound event to fire before I call mylistview.databind(); ----> NO ... only when you bind the data the item data bound will be called, the event name says its all, only when the item is bound with data(which will happen when databind is called..)
0
guru_samiCommented:
As mentioned by masterpass the answer to you question is NO.

But there could be a work around if you can explain some more about the main issue and some code you have tried

--->if this is not the case my control flags a null reference exception error.
-->as my thrid party control will hold different value depending on each row.

so you mean your LV values are dependent on 3rd party control values or the other way...
or how are they inter-related?
0
aspnet-scotlandAuthor Commented:
I have a test web site setup at the below location so you can debug through my issues. Simply open the web site from VS2008 and run (but you have to have sql server 2008 express installed to open the database connection), as you can see my main calls are made from SetRatingUserIdAndBind(); ...

http://www.tradeselector.co.uk/Misc/ListView_Rating.zip

Thanks.
0
aspnet-scotlandAuthor Commented:
guru_sami,

What I meant was that my thrid party control needs to be bound before my listview but the catch 22 is that the control requires the items from my listview as it resides within the itemtemplate of my listview. I hope I've made that clear?

Thanks.
0
aspnet-scotlandAuthor Commented:
I had to set my rating control within my default.aspx page to the below, i.e. physically setting the ItemId to the selected UserId...

<isp:ContentRating
ID="Rating1"
runat="server"
LegendText="rates: {0} avg: {1}"
OnRated="ContentRating1_Rated"
OnRating="ContentRating1_Rating"
OnDataBinding="Rating_DataBinding"
ItemId='<%# Eval("UserId") %>' />

and then alter my Rating_DataBinding event to the below so I'm getting the UserId from the sending control...

using (TradeSelectorDataContext db = new TradeSelectorDataContext())
        {
            int[] rateValues;


            Spaanjaars.Toolkit.ContentRating ratingControl = (Spaanjaars.Toolkit.ContentRating)sender;


            var usrId = ((Guid)ratingControl).ItemId;


            // Get the item through LINQ. SingleOrDefault returns NULL when the item is not found.
            tblTraderRating result = (from tr in db.tblTraderRatings
                                      where tr.UserId == usrId)
                                      select tr).SingleOrDefault();


            if (result == null)
            {
                // Initialize to zero's
                rateValues = new int[] { 0, 0, 0, 0, 0 };
            }
            else
            {
                // Get the values from the result Rating instance.
                rateValues = new int[]
                {
                    result.Rating01
                    , result.Rating02
                    , result.Rating03
                    , result.Rating04
                    , result.Rating05
                };
            }

            //ratingControl.ItemId = UserId;
            ratingControl.DataSource = rateValues;
        }

This populated my listview with my multiple UserId values and their individual rating values.

Thanks!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.