Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

not sure why this is not working.

Posted on 2006-07-13
4
Medium Priority
?
252 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 400 total points
ID: 17098671
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
ID: 17098700
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
ID: 17098760
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
ID: 17098762
thanks for the help.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

927 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