Acting on contents of a declartivly databound Drop Down List?

M

mc

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
}

......
 
W

Walter Wang [MSFT]

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 ([email protected], 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top