Data binding DropDownList user control within other user controls

Data binding DropDownList user control within other user controls

Post by Keith Geringe » Thu, 01 Aug 2002 03:00:06

I have a user control with a DataList object on it.  Within the
<EditItemTemplate> I have a user control that is a special DropDownList

<asp:DataList ID="usercontrol1" Runat="Server"

    <asp:Button ID="btnEdit" Runat="server" Text="Edit" CommandName="Edit"
CommandArgument='<%# Container.DataItem("ID") %>' />
    <asp:Label ID="lblItem" Runat="server" Text='<%#
Container.DataItem("Line") %>' />
    <mytag:MyDropDownList ID="ddlDropDownList" Runat="server"
SelectedValue='<%# Container.DataItem("Value") %>' />

My MyDropDownList component on page load calls a method that takes the
SelectedValue and sets the SelectedIndex of the DropDownList object in
MyDropDownList object.  When I do this I receive "Object reference not set
to an instance of an object" errors.  I've run tests and have found that the
SelectedValue property doesn't have a value either.  It acts like the object
doesn't exist yet.

What do I have to do?  What is the firing order of methods when I perform a
databind on the datalist?
Am I at least close?

Thanks, Keith Geringer


1. web user control within a web user control

Have web user control that contains four buttons and one a user clicks
a button another web user control is posted to the placeholder.  My
question is after the user enters some data into the textbox and
clicks submit, the child web user control goes away( which i
understand as page_load being called for parent web user control ) and
my database code never gets executed.  I load the child web user
controls dynamically, which is rendered from the use selecting a
particular button.  I have seen several responses to this, but nothing
that as provided answer.  I do understand that the child web user
control is no longer load.


private void Page_Load(object sender, System.EventArgs e)
if( Page.IsPostBack )
AddNewProject.Enabled = true;
AddNewComponent.Enabled = true;
DeleteComponent.Enabled = true;
RegisterUsers.Enabled = true;

private void DisplayControl( )
this.plcContent.Controls.Add( Page.LoadControl( "~/Administrators/" +
PageName + ".ascx" ) );
this.ShowSelection( PageName );
catch( Exception )
this.plcContent.Controls.Add( new System.Web.UI.LiteralControl(
"Invalid Selection!" ) );

private void ShowSelection( string sPage )
Button l_Button = (Button)this.FindControl( sPage );
l_Button.Enabled = false;

private void DeleteComponent_Click(object sender, System.EventArgs e)
PageName = "DeleteComponent";
DisplayControl( );

private void AddNewComponent_Click(object sender, System.EventArgs e)
PageName = "AddNewComponent";        
DisplayControl( );

private void AddNewProject_Click(object sender, System.EventArgs e)
PageName = "AddNewProject";
DisplayControl( );

private void RegisterUsers_Click(object sender, System.EventArgs e)
PageName = "RegisterUsers";          
DisplayControl( );

2. safe "practices"

3. Calling user control methods within user controls

4. Computer switchboxes

5. Custom control vs User control / Sizing controls within custom control

6. Dos.h

7. Data Binding within Data Bound Controls.

8. Norton Int. Sec. & MS Exchange

9. Selecting an Item in a DropDownList within a User Control

10. Identifying authenticated users within a user control

11. web controls within user control not firing Init event from C#

12. How do I implement two-way data binding in a user-control

13. Data Bound user control