Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 15th, 2003, 01:24 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I'm a little confused by your intent here... why are you trying to dig into the user control like this? Have we moved on from the original topic of databinding?

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old December 15th, 2003, 01:34 PM
Authorized User
 
Join Date: Oct 2003
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Right... I'm struggling as to how to get the selected value from the user control that has been successfully databound. Your PreRender suggestion worked perfectly. Now I can't figure out how to get to that control to find out what was selected when my form posts back.

"A spirit with a vision is a dream with a mission"
 
Old December 15th, 2003, 01:59 PM
Authorized User
 
Join Date: Oct 2003
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I realized that the control is rendering on the page before I can call the submit method, so it is returning the correct selected index.... 0 .... aach. Suggestions?

"A spirit with a vision is a dream with a mission"
 
Old December 15th, 2003, 02:23 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Ok. I see what you want now. If you want to return a value of an user control's internal control you should create a public method on the user control to expose it. If you really need to, you could make the control (dropdown list in your case) public on the control but in most cases, you are only interested in the value/text/item.

Create a public property on the UserControl that exposes the selected Item/Value/Text, whichever you need. So in your user control class, do something like this:

Public Readonly Property AccountNumber() As String
    Get
        Return ddlAccountList.SelectedValue
    End Get
End Property

Now in the page, you can get that value: ucAccountListControl.AccountNumber.

In addition, you might also want to create an event for when the account number changes so you don't need to "get" it every time. This follows the event driven model of .net. In the user control:

Public Event AccountNumberChanged(sAccountNum As String)

In the DDL OnSelectedItemChanged handler:

RaiseEvent AccountNumberChanged(ddl.SelectedValue)

Something to that affect is what you want.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old February 12th, 2008, 02:01 AM
Registered User
 
Join Date: Feb 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to coomart
Default

protected void LocationDataBound(object sender, EventArgs e)
    {
        locations_ddl.ClearSelection();
        locations_ddl.Items.FindByValue(Location_Id_IN).Se lected = true;
    }

    public string Location_Id_IN
    {
        set
        {
            ViewState["loc_id"] = value;
        }

        get
        {
            return (string)ViewState["loc_id"];
        }
    }

    public string Location_Id
    {
        set
        {
            Location_Id_IN = value;
        }

        get
        {
            return locations_ddl.SelectedValue;
        }
    }

This works!!!

ex: <control:location id="id1" runat="server" Location_Id='<%# Bind("LOCATION_ID")%>'/>

&gt;|&lt; &lt;&gt; &lt;&gt; |\/| /\ |&gt; "|"





Similar Threads
Thread Thread Starter Forum Replies Last Post
Phantom Databinding on drop down list Jerminator ASP.NET 1.x and 2.0 Application Design 0 February 6th, 2008 12:33 AM
Databinding Parent Dropdown from Popup bijukprm ASP.NET 2.0 Basics 0 September 5th, 2007 11:49 PM
Dropdown list maha .NET Framework 2.0 7 April 28th, 2007 12:32 AM
fill dropdown list with items when parent list isaac_cm Pro PHP 1 July 10th, 2006 05:41 AM
usercontrol dropdown list... help forkhead ASP.NET 1.0 and 1.1 Professional 1 November 19th, 2003 06:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.