ListBox - Selected Item

I have a .ascx file that loads client info into an asp datalist. On this file there is an edit button that allows the user to edit this client information and will switch the display from <ItemTemplate> to the <EditItemTemplate>. I have an asp listbox within the <EditItemTemplate> that looks like this:<BR><BR><asp:ListBox id="StatusList" runat="server"><BR><asp:ListItem Value=http://aspmessageboard.com/archive/index.php/"Active">Active</asp:ListItem><BR><asp:ListItem Value="Pending">Pending</asp:ListItem><BR></asp:ListBox><BR><BR>I want to select the matching record from the database and make that item selected within the list. I use a case statement to do this because the data is text. I can get the value I need selected but when it is time to select the record using:<BR><BR>StatusList.SelectedIndex = 0<BR><BR>I get the following error:<BR><BR>Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.<BR><BR>Now when I was using VS.NET it will put all the web controls I use within the .ascx file and place it in the VB file attached to it. I noticed that it would not add the controls you place within the <EditItemTemplate> on an asp datalist control I had to add this line myself:<BR><BR>Protected WithEvents StatusList As System.Web.UI.WebControls.ListBox<BR><BR>How can I select an item from a listbox if the control within a <EditItemTemplate> will not register when the page loads?
 
Back
Top