Thursday, March 29, 2012
Populate .net dropdown
is region which holds a list of states/provinces/countys relating to that
country.
How do I populate a combo so that it is indented.
e.g
USA
-Florida
-California
-Utah
Canada
-Ontario
-Quebec
England
-Kent
-Northumberland
TIAYou get real familiar with the dropdownlist.add() method, because this isn't
something you are going to acheive with the standard way of doing things.
First you have to design a query to return
countries/states/provinces/countys sorted by country, then you have to loop
through them, set some variable to the current country, and then pop either
a Country, or a state/province/county in the dropdownlist using the .add
method. If it is a state/province/county you'll probably need to add
something to the beginning to actually indent it. Then you'll have the
problem of finding out if they selected a country or a
state/province/county.
sounds fun!
"Poppy" <paul.diamond@.NOSPAMthemedialounge.com> wrote in message
news:%23ndPZP32DHA.556@.TK2MSFTNGP11.phx.gbl...
> I have 2 tables. One is country and holds a list of countries and the
other
> is region which holds a list of states/provinces/countys relating to that
> country.
> How do I populate a combo so that it is indented.
> e.g
> USA
> -Florida
> -California
> -Utah
> Canada
> -Ontario
> -Quebec
> England
> -Kent
> -Northumberland
> TIA
Wednesday, March 21, 2012
populating a dropdown list from arraylist of objects
i have an arraylist which holds my Customer object, that contains the
customer details, but when i try binding it to a dropdown box, i cant get
the values to appear..
this is what i tried:
customerList.DataSource = Customer.GetAdminList()
customerList.DataBind()
customerList.DataTextField = CType(customerList.DataSource,
Customer).Email.ToString
customerList.DataValueField = CType(customerList.DataSource,
Customer).CustomerID.ToString
customerList.Items.Insert(0, "--ALL CUSTOMERS--")
this error returns me a invalid cast error..so i also tried the normal
method:
customerList.DataSource = DotcoCustomer.GetAdminList()
customerList.DataBind()
customerList.DataTextField = "email"
customerList.DataValueField = "customerID"
customerList.Items.Insert(0, "--ALL CUSTOMERS--")
but this populates the dropdown list with the the values
"Web2004.Customer" - which is my application namespace.Object...'
any help appreciated,
Paul.Rearrange the order of your code:
customerList.DataSource = DotcoCustomer.GetAdminList()
customerList.DataTextField = "email"
customerList.DataValueField = "customerID"
customerList.DataBind()
customerList.Items.Insert(0, "--ALL CUSTOMERS--")
"Paul M" <milsnips@.hotmail.com> wrote in message
news:uf9aWLvQEHA.3568@.TK2MSFTNGP10.phx.gbl...
> hi there,
> i have an arraylist which holds my Customer object, that contains the
> customer details, but when i try binding it to a dropdown box, i cant get
> the values to appear..
> this is what i tried:
> customerList.DataSource = Customer.GetAdminList()
> customerList.DataBind()
> customerList.DataTextField = CType(customerList.DataSource,
> Customer).Email.ToString
> customerList.DataValueField = CType(customerList.DataSource,
> Customer).CustomerID.ToString
> customerList.Items.Insert(0, "--ALL CUSTOMERS--")
> this error returns me a invalid cast error..so i also tried the normal
> method:
>
> customerList.DataSource = DotcoCustomer.GetAdminList()
> customerList.DataBind()
> customerList.DataTextField = "email"
> customerList.DataValueField = "customerID"
> customerList.Items.Insert(0, "--ALL CUSTOMERS--")
>
> but this populates the dropdown list with the the values
> "Web2004.Customer" - which is my application namespace.Object...'
> any help appreciated,
> Paul.
>
>
populating a dropdown list from arraylist of objects
i have an arraylist which holds my Customer object, that contains the
customer details, but when i try binding it to a dropdown box, i cant get
the values to appear..
this is what i tried:
customerList.DataSource = Customer.GetAdminList()
customerList.DataBind()
customerList.DataTextField = CType(customerList.DataSource,
Customer).Email.ToString
customerList.DataValueField = CType(customerList.DataSource,
Customer).CustomerID.ToString
customerList.Items.Insert(0, "--ALL CUSTOMERS--")
this error returns me a invalid cast error..so i also tried the normal
method:
customerList.DataSource = DotcoCustomer.GetAdminList()
customerList.DataBind()
customerList.DataTextField = "email"
customerList.DataValueField = "customerID"
customerList.Items.Insert(0, "--ALL CUSTOMERS--")
but this populates the dropdown list with the the values
"Web2004.Customer" - which is my application namespace.Object...??
any help appreciated,
Paul.Rearrange the order of your code:
customerList.DataSource = DotcoCustomer.GetAdminList()
customerList.DataTextField = "email"
customerList.DataValueField = "customerID"
customerList.DataBind()
customerList.Items.Insert(0, "--ALL CUSTOMERS--")
"Paul M" <milsnips@.hotmail.com> wrote in message
news:uf9aWLvQEHA.3568@.TK2MSFTNGP10.phx.gbl...
> hi there,
> i have an arraylist which holds my Customer object, that contains the
> customer details, but when i try binding it to a dropdown box, i cant get
> the values to appear..
> this is what i tried:
> customerList.DataSource = Customer.GetAdminList()
> customerList.DataBind()
> customerList.DataTextField = CType(customerList.DataSource,
> Customer).Email.ToString
> customerList.DataValueField = CType(customerList.DataSource,
> Customer).CustomerID.ToString
> customerList.Items.Insert(0, "--ALL CUSTOMERS--")
> this error returns me a invalid cast error..so i also tried the normal
> method:
>
> customerList.DataSource = DotcoCustomer.GetAdminList()
> customerList.DataBind()
> customerList.DataTextField = "email"
> customerList.DataValueField = "customerID"
> customerList.Items.Insert(0, "--ALL CUSTOMERS--")
>
> but this populates the dropdown list with the the values
> "Web2004.Customer" - which is my application namespace.Object...??
> any help appreciated,
> Paul.
Friday, March 16, 2012
populating asp:dropdownlist programmatically
I'd like to create this programmatically rather than have to hardcode it
into the page.
For example
<asp:DropDownList id="numYears" runat="server" name="numYears">
<asp:ListItem Value="0" Text="0 years" Selected="true" />
<asp:ListItem Value="1" Text="1 year"/>
<asp:ListItem Value="2" Text="2 year"/>
<asp:ListItem Value="2" Text="2 year"/>
<asp:ListItem Value="3" Text etc.......... up to 250 years
Thanks in advance..
Simon AmesHi,
put the DDL declaration at the Page (or create it in code just as you see
better).
<asp:DropDownList ID="ddl1" Runat="server">
</asp:DropDownList
Then say in Page_Load:
= = =
if(!Page.IsPostBack)
{
for(int i=0;i<251;i++)
{
ListItem litem=new ListItem(i.ToString() + " years",i.ToString());
ddl1.Items.Add(litem);
}
ddl1.SelectedIndex =0;
}
= = =
--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
"amessimon" <amessimon@.hotmail.com> wrote in message
news:e1ZyKV4AEHA.744@.TK2MSFTNGP10.phx.gbl...
I need to display a drop down list which holds up to 250 listitems.
I'd like to create this programmatically rather than have to hardcode it
into the page.
For example
<asp:DropDownList id="numYears" runat="server" name="numYears">
<asp:ListItem Value="0" Text="0 years" Selected="true" />
<asp:ListItem Value="1" Text="1 year"/>
<asp:ListItem Value="2" Text="2 year"/>
<asp:ListItem Value="2" Text="2 year"/>
<asp:ListItem Value="3" Text etc.......... up to 250 years
Thanks in advance..
Simon Ames
Hello Simon
"amessimon" <amessimon@.hotmail.com> schrieb im Newsbeitrag
news:e1ZyKV4AEHA.744@.TK2MSFTNGP10.phx.gbl...
> I need to display a drop down list which holds up to 250 listitems.
> I'd like to create this programmatically rather than have to hardcode it
> into the page.
> For example
> <asp:DropDownList id="numYears" runat="server" name="numYears">
> <asp:ListItem Value="0" Text="0 years" Selected="true" />
> <asp:ListItem Value="1" Text="1 year"/>
> <asp:ListItem Value="2" Text="2 year"/>
> <asp:ListItem Value="2" Text="2 year"/>
> <asp:ListItem Value="3" Text etc.......... up to 250 years
for (int i=0; i<=250; i++)
{
numYears.Items.Add(i.ToString());
}
mfg simon g.