Link to home
Start Free TrialLog in
Avatar of watherton
watherton

asked on

not sure why this is not working.

hi guys

i have a usercontrol that populates a dropdown list. I want the SelectedItem.Value to be used to populate another user control value I have exposed the properties on the first usercontrol as follows:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


using CapitalIncentives.Clients;


namespace CapitalIncentives.UserInterface
{
    public partial class ClientList : System.Web.UI.UserControl
    {
        public DataSet clients;

        public int clientID;

        protected string[] validationErrors = null;

        private ArrayList errorList = new ArrayList(1);

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BuildClientsDropDown();
            }
        }

        public void BuildClientsDropDown()
        {
            try
            {
                using (CapitalIncentives.Clients.ClientManagement clientManagement = new CapitalIncentives.Clients.ClientManagement())
                {

                    clientManagement.GetCurrentClientList(out clients);
                    if (clients != null)
                    {
                        DataColumn newColumn = new DataColumn();

                        newColumn.ColumnName = "fullClient";

                        newColumn.DataType = System.Type.GetType("System.String");

                        newColumn.Expression = "ClientNumber+' -- '+ClientName";

                        clients.Tables[0].Columns.Add(newColumn);

                        ddClients.DataSource = clients;
                        ddClients.DataTextField = "fullClient";
                        ddClients.DataValueField = "ClientID";
                        ddClients.DataBind();
                        ddClients.Items.Insert(0, new ListItem("--Please select--", "0"));
                    }

                    // Check if there are any clients registered
                    if (clients.Tables[0].Rows.Count == 0)
                    {
                        // If the dataset is equal 0, then disable form content and display message.
                        errorList.Add(@"There are no clients." + System.Environment.NewLine);
                        validationErrors = (string[])errorList.ToArray(typeof(string));
                    }
                }
            }
            catch (Exception error)
            {
                validationErrors = (string[])errorList.ToArray(typeof(string));
                errorList.Add(@"There has been a problem populating the client drop down list." + error.Message);
            }
        }

        public void Client_Changed(Object sender, EventArgs e)
        {
          clientID = int.Parse(ddClients.SelectedItem.Value);
        }
       
        public int ClientID
        {
            get { return clientID; }
            set { ClientID = value; }
           
        }

    }

}

but when i try and get the value within my aspx page, it always returns zero

int clientselected =ClientList.clientID;
ASKER CERTIFIED SOLUTION
Avatar of DarkXiphoid
DarkXiphoid

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of watherton
watherton

ASKER

not sure what you are trying to explain here.

I have a public property that does the following : (this has changed since posting above)


// User Control public property
public int SelectedClient
{

}
sorry pressed the wrong button

....


// User Control public property
 public int SelectedClient
        {
            get { return int.Parse(ddClients.SelectedItem.Value); }
            set { clientID = value; }
           
        }

then in my aspx page I do the following:

public int selectedClient;

selectedClient = clientlist.clientID;


oh pants, I've just spotted my mistake, I should have this


selectedClient = clientlist.SelectedClient
thanks for the help.