asp.net building controls:
I've developed a custom access list user control. The control has a drop down list of people which is populated using a sqlDataSource Whenever I try to refrence the items in the list of people I get a null object error. I can refrence the control ok but in Page_Init / Page_Load / Page_PreRender the ddlPeople.items.count == 0 If the user creates my control with the TaskTeamTaskID property set I want to act upon the items in the drop down list during the page initalisation. I've included some code, I've had to retype the code so I've left bit's out and probalbly got bits wrong but should be enough to get a feel for what I'm doing. My Question is when is it safe to call "init_taskTeamLists()" -----TestPage.aspx----- ...... <uc1:UpdateTaskTeam ID="UpdateTaskTeam1" TaskTeamId="42" runat="server /> ...... -----UpdateTaskTeam.ascx----- <%@ Control Language="C#" AutoEventWireup="true" CodeFile="UpdateTaskTeam.ascx.cs" Inherits="UpdateTaskTeam" %> <asp:SqlDataSource ID="sdsPeople" runat="server" SelectCommandType="StoredProcedure" SelectCommand="AllPeople" ConnectionString="<%$ ConnectionStrings:TTT%>" /> <asp:DropDownList ID="ddlPeople" runat="server" DataSourceId="sdsPeople" DataTextField="fullname" DataValueField="staffnumber" /> ...... <asp:ListBox ID="lbReadOnly" runat="server" /> <asp:ListBox ID="lbReadWrite" runat="server" /> ...... -----UpdateTaskTeam.ascx.cs----- ....... public int TaskTeamTaskId { get{ return Int32.Parse(hfTaskTeamTaskId.Value.ToString()); } set{ hfTaskTeamTaskId.Value = value.ToString(); } } ...... private void init_taskTeamLists() { //Do some DB stuff to get the current Task Team List //If Person.access == Read Only // Move from the People List to the Read Only List //else if person.access == ReadWrite // Move from the People List to the ReadWrite List }
Hi, Thank you for your post. Based on my understanding, you question is: 1) You have a UserControl which has a data-bound DropDownList bound to a SqlDataSource 2) You want to know when is the data available (bound to DropDownList) If I've misunderstood anything, please feel free to post here. I think the best place to call init_taskTeamLists() is in DropDownList's DataBound event, this event is fired after the data bound to the DropDownList from the SqlDataSource. Hope this helps. Please feel free to post here if anything is unclear. Regards, Walter Wang (wawang@online.microsoft.com, remove 'online.') Microsoft Online Community Support ================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights.
Don't see what you're looking for? Try a search.
|