|
 |
aspx thread: How can do with DropList Value ?
Message #1 by "Alessandro Betti" <betti@t...> on Fri, 16 Mar 2001 09:53:34 +0100
|
|
In "OLD ASP" i can put a Text and value in a combo
combo.addItem text,value
How can do the same in ASP.NET ?
I try with ListItemCollection but nothing happens....
I write the code that i had use
sub LoadCboNation()
dim com as object
dim dbArray as Object
dim t as integer
dim lista as ListItemCollection = new ListItemCollection()
com = Server.createobject(CO.UTILITIES)
dbArray =com.GetSubSetQuery("Com_Name")
com = nothing
if (dbArray<>DBNull) then
for t=0 to Ubound(dbArray,2)
Lista.add(dbArray(1,t),dbArray(0,t))
next t
end if
cboNa.DataSource = Lista
cboNa.DataBind()
end sub
Thanks
Betti ALessandro
Message #2 by "dave" <support@1...> on Fri, 16 Mar 2001 07:27:19 -0600
|
|
Here you go, I just posted a sample....
http://www.123aspx.com/resdetail.asp?rid=821
Cheers!
dave
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
http://www.123aspx.com
The Largest ASP.NET Directory!
Find the latest ASP.NET resources --
Subscribe to our newsletter!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
----- Original Message -----
From: "Alessandro Betti" <betti@t...>
To: "ASP+" <aspx@p...>
Sent: Friday, March 16, 2001 11:47 AM
Subject: [aspx] How can do with DropList Value ?
> In "OLD ASP" i can put a Text and value in a combo
>
> combo.addItem text,value
>
> How can do the same in ASP.NET ?
> I try with ListItemCollection but nothing happens....
> I write the code that i had use
>
> sub LoadCboNation()
> dim com as object
> dim dbArray as Object
> dim t as integer
> dim lista as ListItemCollection = new ListItemCollection()
>
> com = Server.createobject(CO.UTILITIES)
> dbArray =com.GetSubSetQuery("Com_Name")
> com = nothing
>
>
>
> if (dbArray<>DBNull) then
> for t=0 to Ubound(dbArray,2)
>
> Lista.add(dbArray(1,t),dbArray(0,t))
>
> next t
> end if
>
> cboNa.DataSource = Lista
> cboNa.DataBind()
>
> end sub
>
> Thanks
> Betti ALessandro
>
Message #3 by John Pirkey <mailjohnny101@y...> on Fri, 16 Mar 2001 08:29:27 -0800 (PST)
|
|
Since you are binding the listbox to a datatable - why not set this up when you
declare the control. Lets assume you want to bind a list box to a customer table -
showing CustomerName, but using CustomerID as the value. Declare your control like
this:
<asp:DropDownList id="cbocustomers" runat="server"
DataTextField="CustomerName"
DataValueField="CustomerID"
OnSelectedIndexChanged="cbocustomers_click" />
Then in the Page_Load routine, check for Page.IsPostBack = False, which the first
time the page is requested, and when setting up your datatables and such:
Sub Page_Load(Sender As Object, E As EventArgs)
If Not IsPostBack Then
dim cn as adoconnection
dim cmd as adodatasetcommand
dim ds as new dataset
dim connstr as string
dim sql as string
connstr = "provider=sqloledb;server=<YOUR_SERVER>db;user
id=<YOUR_USERID>;password=<YOUR_PASSWORD>;Database=<YOUR_DATABASE>;"
cn = new adoconnection(connstr)
sql = "select CustomerID, CustomerName from customers (nolock) order by
customername"
cmd = new adodatasetcommand(sql, cn)
cmd.filldataset(ds, "customers")
cbocustomers.datasource = ds.tables("customers").defaultview
page.databind()
End if
End Sub
Now, when you request your page - the combo box will show all the customer names,
and their values. To get these values back - ask for them like this:
cbocustomers.selecteditem.text - the customer name
cbocustomers.selecteditem.value - the customer id
there are some other examples of this in the Framework SDK for .Net as well as other
websites - check out www.aspfree.com they have a lot of examples. the above code
was from one of my website's examples, www.stlvbug.org.
hope this helps,
john
--- Alessandro Betti <betti@t...> wrote:
> In "OLD ASP" i can put a Text and value in a combo
>
> combo.addItem text,value
>
> How can do the same in ASP.NET ?
> I try with ListItemCollection but nothing happens....
> I write the code that i had use
>
> sub LoadCboNation()
> dim com as object
> dim dbArray as Object
> dim t as integer
> dim lista as ListItemCollection = new ListItemCollection()
>
> com = Server.createobject(CO.UTILITIES)
> dbArray =com.GetSubSetQuery("Com_Name")
> com = nothing
>
>
>
> if (dbArray<>DBNull) then
> for t=0 to Ubound(dbArray,2)
>
> Lista.add(dbArray(1,t),dbArray(0,t))
>
> next t
> end if
>
> cboNa.DataSource = Lista
> cboNa.DataBind()
>
> end sub
>
> Thanks
> Betti ALessandro
=====
----------------------------
John Pirkey
MCSD
John@S...
http://www.stlvbug.org
|
|
 |