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.UserInte rface
{
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 .ClientMan agement clientManagement = new CapitalIncentives.Clients. ClientMana gement())
{
clientManagement.GetCurren tClientLis t(out clients);
if (clients != null)
{
DataColumn newColumn = new DataColumn();
newColumn.ColumnName = "fullClient";
newColumn.DataType = System.Type.GetType("Syste m.String") ;
newColumn.Expression = "ClientNumber+' -- '+ClientName";
clients.Tables[0].Columns. Add(newCol umn);
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.Co unt == 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.ToArra y(typeof(s tring));
}
}
}
catch (Exception error)
{
validationErrors = (string[])errorList.ToArra y(typeof(s tring));
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.Select edItem.Val ue);
}
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;
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.
using System.Web.UI.HtmlControls
using CapitalIncentives.Clients;
namespace CapitalIncentives.UserInte
{
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.GetCurren
if (clients != null)
{
DataColumn newColumn = new DataColumn();
newColumn.ColumnName = "fullClient";
newColumn.DataType = System.Type.GetType("Syste
newColumn.Expression = "ClientNumber+' -- '+ClientName";
clients.Tables[0].Columns.
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.Co
{
// 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.ToArra
}
}
}
catch (Exception error)
{
validationErrors = (string[])errorList.ToArra
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.Select
}
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
sorry pressed the wrong button
....
// User Control public property
public int SelectedClient
{
get { return int.Parse(ddClients.Select edItem.Val ue); }
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
....
// User Control public property
public int SelectedClient
{
get { return int.Parse(ddClients.Select
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
ASKER
thanks for the help.
ASKER
I have a public property that does the following : (this has changed since posting above)
// User Control public property
public int SelectedClient
{
}