Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Building Controls / June 2006

Tip: Looking for answers? Try searching our database.

Acting on contents of a declartivly databound Drop Down List?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mc - 23 Jun 2006 15:02 GMT
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
}

.....
Walter Wang [MSFT] - 26 Jun 2006 04:56 GMT
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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.