Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

not sure why this is not working.

Posted on 2006-07-13
4
248 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
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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 video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

860 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