By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,737 Members | 1,506 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,737 IT Pros & Developers. It's quick & easy.

asp.net 2.0 data access driving a novice nuts... inputs are more than welcome

P: n/a
Hello all,
Before I start I'd like to point out that I am a complete novice when
it comes to asp.net - My background is in network and operating
systems, and although I have been doing a bit of hobby programming in
vb.net and web programming in asp/vbscript in the past, I am pretty
much a beginner at asp.net.

What I'm trying to do, is to take the "PersonalHomePage" starter kit
that MS supplies with VS2005 and tweak it a bit, to make it suitable
for my own homepage. The PersonalHomePage starter kit stores all the
photos for its photo album inside a SQL Database, and I'm gonna use a
regular file/folder approach instead, using an Access database to hold
to relationship between albums and photos. So to the problem:

The albums.aspx page shows all my albums, with a link for each of them.
Also, the page shows one photo for each album, so that the visitor can
see an example of photos the particular album holds.

To list the albums is easy enough - I use a DataList and an
AccessDataSource that queries all my albums. The DataList automatically
repeats itself the number of records in the DB, and I can use the <%
#Eval("AlbumName") %> tag to display the Name and ID of each album, as
well as generate a link for taking the visitor to the selected album
(something like albums.aspx?id=<%# Eval("AlbumID") %> or thereabouts)

Here's the tricky one: I'd like to have a second AccessDataSource which
accepts AlbumID as a parameter and generates the URL for the photo. In
my "Photos" table I already have a field for ImageURL, so displaying
photo for each of the albums should simply be a matter of getting this
ImageURL into the "img src=" part of the code.

However:
-I am not allowed to have more than one AccessDatasources for a
DataList, so I can't do an "Eval" on more than one datasource per
DataList.

-I could create the datasource for the image in the code-behind file
inside a function which accepts AlbumID as a parameter and return a
ImageURL to the aspx page. However, this would give me the code
(assuming that the function is named GetImageUrl):

img src=<%GetImageUrl( <%# Eval ("AlbumID") %> ) %>

which of course is not allowed, as it is two "nested" scripts.

I know I could do this by constructing a second page called
imagehandler.aspx or whatever, that would take the album as a parameter
and return the image as a stream, but I was hoping to avoid using
advanced stuff like streams here (small steps etc..).

The things that are driving me nuts are:
1.I know how to do this with Dreamweaver version ca 2001 using regular
asp, here I was able to parameterize pretty much whatever I wanted
without using server controls, which I guess in a way was more of a
hassle, but at least I had full control over the entire page.

2. When looking at documentation (both in msdn and in books24x7.com,
whenever I look for "asp.net 2.0 data access" all I get are the "Build
data-driven pages witout a single line of code!". I gotta say, I'm more
interested in solid examples than making software without coding :-)

Of course, I know that this is beta stuff, and as such, not fully
documented. And when posting this, one of you asp.net experts are
probable going to make me eat my words by showing me how I can achieve
what I want here with only two lines of code, but still: I can't help
but feel that anything that requires me to "pop the hood" and go beyond
the wizard-driven stuff is getting harder and harder - not easier and
easier...

Any comments or helpful hints are deeply appreciated. Sorry for making
you read all this :-)

kind regards,
Trond Hindenes
Novice asp.net programmer
Norway

Nov 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

tr***@hindenes.com wrote:
Hello all,
Before I start I'd like to point out that I am a complete novice when
it comes to asp.net - My background is in network and operating
systems, and although I have been doing a bit of hobby programming in
vb.net and web programming in asp/vbscript in the past, I am pretty
much a beginner at asp.net.

What I'm trying to do, is to take the "PersonalHomePage" starter kit
that MS supplies with VS2005 and tweak it a bit, to make it suitable
for my own homepage. The PersonalHomePage starter kit stores all the
photos for its photo album inside a SQL Database, and I'm gonna use a
regular file/folder approach instead, using an Access database to hold
to relationship between albums and photos. So to the problem:

The albums.aspx page shows all my albums, with a link for each of them.
Also, the page shows one photo for each album, so that the visitor can
see an example of photos the particular album holds.

To list the albums is easy enough - I use a DataList and an
AccessDataSource that queries all my albums. The DataList automatically
repeats itself the number of records in the DB, and I can use the <%
#Eval("AlbumName") %> tag to display the Name and ID of each album, as
well as generate a link for taking the visitor to the selected album
(something like albums.aspx?id=<%# Eval("AlbumID") %> or thereabouts)

Here's the tricky one: I'd like to have a second AccessDataSource which
accepts AlbumID as a parameter and generates the URL for the photo. In
my "Photos" table I already have a field for ImageURL, so displaying
photo for each of the albums should simply be a matter of getting this
ImageURL into the "img src=" part of the code.

However:
-I am not allowed to have more than one AccessDatasources for a
DataList, so I can't do an "Eval" on more than one datasource per
DataList.

-I could create the datasource for the image in the code-behind file
inside a function which accepts AlbumID as a parameter and return a
ImageURL to the aspx page. However, this would give me the code
(assuming that the function is named GetImageUrl):

img src=<%GetImageUrl( <%# Eval ("AlbumID") %> ) %>

which of course is not allowed, as it is two "nested" scripts.

I know I could do this by constructing a second page called
imagehandler.aspx or whatever, that would take the album as a parameter
and return the image as a stream, but I was hoping to avoid using
advanced stuff like streams here (small steps etc..).

The things that are driving me nuts are:
1.I know how to do this with Dreamweaver version ca 2001 using regular
asp, here I was able to parameterize pretty much whatever I wanted
without using server controls, which I guess in a way was more of a
hassle, but at least I had full control over the entire page.

2. When looking at documentation (both in msdn and in books24x7.com,
whenever I look for "asp.net 2.0 data access" all I get are the "Build
data-driven pages witout a single line of code!". I gotta say, I'm more
interested in solid examples than making software without coding :-)

Of course, I know that this is beta stuff, and as such, not fully
documented. And when posting this, one of you asp.net experts are
probable going to make me eat my words by showing me how I can achieve
what I want here with only two lines of code, but still: I can't help
but feel that anything that requires me to "pop the hood" and go beyond
the wizard-driven stuff is getting harder and harder - not easier and
easier...

Any comments or helpful hints are deeply appreciated. Sorry for making
you read all this :-)

kind regards,
Trond Hindenes
Novice asp.net programmer
Norway


Nov 19 '05 #2

P: n/a
Try using a sql statement with joins to multiple tables.

Nov 19 '05 #3

P: n/a
no. Your list will have a text and value information and you want to
also get the image url [and contain it in the list]. You could do a
postback image url lookup after each user change event to the list.
Possibly pull all three fields in inital db pull and put albumid/url
combination in viewstate for use when user list change event occurs.

If you want something easy, use a datagrid, which can have
visible=false columns to hide url.

-K

Nov 19 '05 #4

P: n/a
You should be able to do as many eval() statements, concatenated with a
'+' as you want.

Nov 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.