Showing posts with label generate. Show all posts
Showing posts with label generate. Show all posts

Thursday, March 29, 2012

NEWBIE - Multicolumn Listbox populated from SQL statement

Greetings,

I am attempting to generate a multicolumn listbox from a SQL statement in
ASP.NET. Below is my SQL Statement:

SELECT [PA01101].[PACONTNUMBER], [PA01101].[PAcontname] FROM [PA01101]

I would like a two column list box with [PACONTNUMBER] on the left and
[PAcontname] on the right. I can do this in MS Access with no problem, but
I do not know to get my datareader info into a multicolumn listbox. I can
do one column of data just fine, but cannot add the second column.

Thank you for your help,

-DaveDeclare the listbox on the .aspx page:
<asp:ListBox runat="server" id="LB" /
Then in code-behind, add the items as you iterate through the repeater:
'Get Repeater 'Data'...
While ( Data.Read() )
LB.Items.Add(New ListItem(Data.Item("Field1") + "-" + Data.Item("Field2"), Data.Item("Field1")))
End While

Note: The above code will have [Field1-Field2] as the text field and [Field1] as the value field for each item in the SqlDataReader

"RockNRoll" wrote:

> Greetings,
> I am attempting to generate a multicolumn listbox from a SQL statement in
> ASP.NET. Below is my SQL Statement:
> SELECT [PA01101].[PACONTNUMBER], [PA01101].[PAcontname] FROM [PA01101]
> I would like a two column list box with [PACONTNUMBER] on the left and
> [PAcontname] on the right. I can do this in MS Access with no problem, but
> I do not know to get my datareader info into a multicolumn listbox. I can
> do one column of data just fine, but cannot add the second column.
> Thank you for your help,
> -Dave
>
concatenate two columns into one in your sql query

select column1 + column2 as multicolumn
from mytable

then have your datareader use "multicolumn" as your textfield. You'll probably have to do some spacing on top of this if you want the results in actual columns, but that should be easy enough.

Also there is a third party control that does multi-column listbox and some more stuff
http://easylistbox.com/demoQuickStart.aspx#easy

--Michael

"RockNRoll" <daveweber@.yahoo.com> wrote in message news:eJAoYOkeEHA.3916@.TK2MSFTNGP11.phx.gbl...
> Greetings,
>
> I am attempting to generate a multicolumn listbox from a SQL statement in
> ASP.NET. Below is my SQL Statement:
>
> SELECT [PA01101].[PACONTNUMBER], [PA01101].[PAcontname] FROM [PA01101]
>
> I would like a two column list box with [PACONTNUMBER] on the left and
> [PAcontname] on the right. I can do this in MS Access with no problem, but
> I do not know to get my datareader info into a multicolumn listbox. I can
> do one column of data just fine, but cannot add the second column.
>
> Thank you for your help,
>
> -Dave
>

NEWBIE - Multicolumn Listbox populated from SQL statement

Greetings,
I am attempting to generate a multicolumn listbox from a SQL statement in
ASP.NET. Below is my SQL Statement:
SELECT [PA01101].[PACONTNUMBER], [PA01101].[PAcontname] FROM [PA01101]
I would like a two column list box with [PACONTNUMBER] on the left and
[PAcontname] on the right. I can do this in MS Access with no problem, but
I do not know to get my datareader info into a multicolumn listbox. I can
do one column of data just fine, but cannot add the second column.
Thank you for your help,
-DaveDeclare the listbox on the .aspx page:
<asp:ListBox runat="server" id="LB" />
Then in code-behind, add the items as you iterate through the repeater:
'Get Repeater 'Data'...
While ( Data.Read() )
LB.Items.Add(New ListItem(Data.Item("Field1") + "-" + Data.Item("Field2"), D
ata.Item("Field1")))
End While
Note: The above code will have [Field1-Field2] as the text field and [Field1
] as the value field for each item in the SqlDataReader
"RockNRoll" wrote:

> Greetings,
> I am attempting to generate a multicolumn listbox from a SQL statement in
> ASP.NET. Below is my SQL Statement:
> SELECT [PA01101].[PACONTNUMBER], [PA01101].[PAcontname] FROM [PA01101]
> I would like a two column list box with [PACONTNUMBER] on the left and
> [PAcontname] on the right. I can do this in MS Access with no problem, but
> I do not know to get my datareader info into a multicolumn listbox. I can
> do one column of data just fine, but cannot add the second column.
> Thank you for your help,
> -Dave
>
>
concatenate two columns into one in your sql query
select column1 + column2 as multicolumn
from mytable
then have your datareader use "multicolumn" as your textfield. You'll =
probably have to do some spacing on top of this if you want the results =
in actual columns, but that should be easy enough.
Also there is a third party control that does multi-column listbox and =
some more stuff
http://easylistbox.com/demoQuickStart.aspx#easy
--Michael
"RockNRoll" <daveweber@.yahoo.com> wrote in message =
news:eJAoYOkeEHA.3916@.TK2MSFTNGP11.phx.gbl...
> Greetings,
>=20
> I am attempting to generate a multicolumn listbox from a SQL statement =
in
> ASP.NET. Below is my SQL Statement:
>=20
> SELECT [PA01101].[PACONTNUMBER], [PA01101].[PAcontname] FROM [PA01101]
>=20
> I would like a two column list box with [PACONTNUMBER] on the left and
> [PAcontname] on the right. I can do this in MS Access with no =
problem, but
> I do not know to get my datareader info into a multicolumn listbox. I =
can
> do one column of data just fine, but cannot add the second column.
>=20
> Thank you for your help,
>=20
> -Dave
>=20
>

Thursday, March 22, 2012

Newbie looking for help... Data driven navigation

Is it possible to generate ASP.net website navigation based entirely on SQL queries?

If so, is it better to generate a static sitemap by running these queries only when a change is made to the database,

or

is it better to allow the queries to run "realtime" on page load and whenever a link is clicked?

Sorry if I'm not too clear, I'm still "extremely" wet behind the ears. ;-)

Thanks in advance,

Jeff

Well not sure if this is the answer you are looking for, but Asp.net 2.0 has a very good new feature Site Map where you can use the Site Map Provider to configure your Navigation of your website.


Hi,

Take a look at these tutorials

http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/data/sitemapdatasource.aspx

http://www.asp.net/learn/data-access/tutorial-62-cs.aspx

One thing you might want to do is cache the SiteMap the first time your page load, that way you will avoid unnecessary db roundtrips.

However if your SiteMap is going to be changing all the time than you can leave the caching out.

Goodluck


The second link is exactly what I was looking for. Thanks.

The link you posted is appending an extra character though, breaking the link, so I reposted it below. (This link points to the VB tutorial)

http://www.asp.net/learn/data-access/tutorial-62-vb.aspx

Jeff