Solved

not sure why this is not working.

Posted on 2006-07-13
4
245 Views
Last Modified: 2010-04-16
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;
0
Comment
Question by:watherton
  • 3
4 Comments
 
LVL 4

Accepted Solution

by:
DarkXiphoid earned 100 total points
Comment Utility
Try getting the value from ClientID instead of clientID.

Also, instead of using:

clientID = int.Parse(ddClients.SelectedItem.Value);

You could try

clientID = Convert.ToInt32(ddClients.SelectedValue);

Tell me if it works!
0
 

Author Comment

by:watherton
Comment Utility
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
{

}
0
 

Author Comment

by:watherton
Comment Utility
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
0
 

Author Comment

by:watherton
Comment Utility
thanks for the help.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now