Question : Change ActiveViewIndex on MultiViewControl

I need a way to change the ActiveViewIndex of a multiview control based on some query results. Right now I test to see if I have rows returned from my linq query. If so, set a certain view active. If no rows are returned, I would like to set a different view active. I would like to do this on Page_Load if possible.

Right now I get the fatal "Object reference not set to an instance of an object" error on page load with it bombing at line 12. My count is given a value at runtime so that is not the issue. Can anybody tell me why this is and how to get around it. Code is attached. Any help would be greatly appreciated.

Jason
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
protected void Page_Load(object sender, EventArgs e)
 {
int count = (from st in psgDB.studyTbls where st.patientid_i == Convert.ToInt32(Request.QueryString["PatientId"]) && st.studystatusid_i == 1 select st).Count();
            if (count == 0)
            {
                StudyInfoMultiView.ActiveViewIndex = 1;
            }

            else
            {
                StudyInfoMultiView.ActiveViewIndex = 2;
            }   
}

Answer : Change ActiveViewIndex on MultiViewControl

Had to set the ActiveViewIndex on the Multiviews onInit Event. This worked. The Issue had to do basically with when the control was rendered. Thanks for al of your help.
- Jason

----------------------------------------------------------------------------------------------------------------------------
from .aspx
<asp:MultiView ID="StudyInfoMultiView" runat="server" OnInit="StudyInfoMultiView_Init" />

from codebehind

        protected void StudyInfoMultiView_Init(object sender, EventArgs e)
        {
            eCrystalPSGDBDataContext psgDB = new eCrystalPSGDBDataContext();
            int count = (from st in psgDB.studyTbls where st.patientid_i == Convert.ToInt32(Request.QueryString["PatientId"]) && st.studystatusid_i == 1 select st).Count();
            if (count == 0)
            {
               
                StudyInfoMultiView.ActiveViewIndex = 1;
            }

            else
            {
               
                StudyInfoMultiView.ActiveViewIndex = 2;
            }

           
        }



 
Random Solutions  
 
programming4us programming4us