473,378 Members | 1,609 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Thinking the right way?

Hi All,

I'm new to ASP.Net.

As I understand it, the code and presentation should as much as possible
remain seperate. Code is in the 'codebehind' - Be it a script block at the
top of the page or seperate file. I have a situation where I need to list
the number of related records.

So far, I have a datalist, which displays records along with an indicator of
related records for that record, example... "France (4)" (Four related
records)

What I would like to do is display a messages depending on how many related
records are found
e.g. 'Record' where there is 1 record, and 'Records' where there are 1 or
more records, and 'No Records' where there are zero.

This would probably be quite straight forward in a script block at the point
of display, but I would like to do this the 'proper' way to keep my
presentation and logic seperate.

So...Can anyone advise how I would go about setting a label for each item in
my datalist? Is this done at the point of binding the data? Am I
understanding this correctly?

Heres what I currently have...

<ItemTemplate>
<a href="/show_resorts.aspx?countryid=<%# Container.DataItem("countryid")
%>">
<img src="/assets/images/flags/<%# Container.DataItem("countryid") %>.jpg"
title="View records for <%# Container.DataItem("country") %>"
class="SPDImage" /></br>
<%# Container.DataItem("country") %><br>
<span class="smallprint">(<%# Container.DataItem("Resorts") %>
Resorts)</span>
</a>
</ItemTemplate>

The above is a chunk from my datalist, which is bound to an MS Access
OleDbCommand.

Thanks!

Simon.

--
-
* Please reply to group for the benefit of all
* Found the answer to your own question? Post it!
* Get a useful reply to one of your posts?...post an answer to another one
* Search first, post later : http://www.google.co.uk/groups
* Want my email address? Ask me in a post...Cos2MuchSpamMakesUFat!

--
-
* Please reply to group for the benefit of all
* Found the answer to your own question? Post it!
* Get a useful reply to one of your posts?...post an answer to another one
* Search first, post later : http://www.google.co.uk/groups
* Want my email address? Ask me in a post...Cos2MuchSpamMakesUFat!
Nov 18 '05 #1
4 1035
Have you checked the documentation for the object(s) you are
using to determine if there is a Rowcount property?
--
<%= Clinton Gallagher
A/E/C Consulting, Web Design, e-Commerce Software Development
Wauwatosa, Milwaukee County, Wisconsin USA
NET csgallagher@ REMOVETHISTEXT metromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/

"Simon Harris" <to*********@makesyoufat.com> wrote in message
news:O0**************@TK2MSFTNGP09.phx.gbl...
Hi All,

I'm new to ASP.Net.

As I understand it, the code and presentation should as much as possible remain seperate. Code is in the 'codebehind' - Be it a script block at the top of the page or seperate file. I have a situation where I need to list the number of related records.

So far, I have a datalist, which displays records along with an indicator of related records for that record, example... "France (4)" (Four related records)

What I would like to do is display a messages depending on how many related records are found
e.g. 'Record' where there is 1 record, and 'Records' where there are 1 or more records, and 'No Records' where there are zero.

This would probably be quite straight forward in a script block at the point of display, but I would like to do this the 'proper' way to keep my
presentation and logic seperate.

So...Can anyone advise how I would go about setting a label for each item in my datalist? Is this done at the point of binding the data? Am I
understanding this correctly?

Heres what I currently have...

<ItemTemplate>
<a href="/show_resorts.aspx?countryid=<%# Container.DataItem("countryid") %>">
<img src="/assets/images/flags/<%# Container.DataItem("countryid") %>.jpg" title="View records for <%# Container.DataItem("country") %>"
class="SPDImage" /></br>
<%# Container.DataItem("country") %><br>
<span class="smallprint">(<%# Container.DataItem("Resorts") %>
Resorts)</span>
</a>
</ItemTemplate>

The above is a chunk from my datalist, which is bound to an MS Access
OleDbCommand.

Thanks!

Simon.

--
-
* Please reply to group for the benefit of all
* Found the answer to your own question? Post it!
* Get a useful reply to one of your posts?...post an answer to another one * Search first, post later : http://www.google.co.uk/groups
* Want my email address? Ask me in a post...Cos2MuchSpamMakesUFat!

--
-
* Please reply to group for the benefit of all
* Found the answer to your own question? Post it!
* Get a useful reply to one of your posts?...post an answer to another one * Search first, post later : http://www.google.co.uk/groups
* Want my email address? Ask me in a post...Cos2MuchSpamMakesUFat!

Nov 18 '05 #2
Hi Simon,

I think using good judgement is more important than following 'rules' all
the time. In some situations using script tags inside of the page is just
plain easier to work with and provides better performance to boot.

You can access each element as it's loaded via code, but if you have a
template column this gets to be a hassle that is also pretty slow because
you'll need to query each control using FindControl() then set properties
etc.
There are ItemCreated and ItemDataBound events that you can handle that let
you programmatically catch each of the columns in the dg as they are bound
and assign data to them. It can be done, but using a template tag is often
more efficient and more self-explanatory.

In cases where template expressions get real complex I tend to create
methods on the form that handle the task to keep complex code out of the
page, but for simple expressions I would never hesitate of sticking them
into the page.

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
----------------------------------
Making waves on the Web
"Simon Harris" <to*********@makesyoufat.com> wrote in message
news:O0**************@TK2MSFTNGP09.phx.gbl...
Hi All,

I'm new to ASP.Net.

As I understand it, the code and presentation should as much as possible
remain seperate. Code is in the 'codebehind' - Be it a script block at the
top of the page or seperate file. I have a situation where I need to list
the number of related records.

So far, I have a datalist, which displays records along with an indicator of related records for that record, example... "France (4)" (Four related
records)

What I would like to do is display a messages depending on how many related records are found
e.g. 'Record' where there is 1 record, and 'Records' where there are 1 or
more records, and 'No Records' where there are zero.

This would probably be quite straight forward in a script block at the point of display, but I would like to do this the 'proper' way to keep my
presentation and logic seperate.

So...Can anyone advise how I would go about setting a label for each item in my datalist? Is this done at the point of binding the data? Am I
understanding this correctly?

Heres what I currently have...

<ItemTemplate>
<a href="/show_resorts.aspx?countryid=<%# Container.DataItem("countryid") %>">
<img src="/assets/images/flags/<%# Container.DataItem("countryid") %>.jpg" title="View records for <%# Container.DataItem("country") %>"
class="SPDImage" /></br>
<%# Container.DataItem("country") %><br>
<span class="smallprint">(<%# Container.DataItem("Resorts") %>
Resorts)</span>
</a>
</ItemTemplate>

The above is a chunk from my datalist, which is bound to an MS Access
OleDbCommand.

Thanks!

Simon.

--
-
* Please reply to group for the benefit of all
* Found the answer to your own question? Post it!
* Get a useful reply to one of your posts?...post an answer to another one
* Search first, post later : http://www.google.co.uk/groups
* Want my email address? Ask me in a post...Cos2MuchSpamMakesUFat!

--
-
* Please reply to group for the benefit of all
* Found the answer to your own question? Post it!
* Get a useful reply to one of your posts?...post an answer to another one
* Search first, post later : http://www.google.co.uk/groups
* Want my email address? Ask me in a post...Cos2MuchSpamMakesUFat!

Nov 18 '05 #3
"Rick Strahl [MVP]" <ri********@hotmail.com> wrote in message
news:u4**************@TK2MSFTNGP11.phx.gbl...
Hi Simon,

I think using good judgement is more important than following 'rules' all
the time. In some situations using script tags inside of the page is just
plain easier to work with and provides better performance to boot.
In my experience, inline script tags can be more difficult to maintain that
codebehind.
You can access each element as it's loaded via code, but if you have a
template column this gets to be a hassle that is also pretty slow because
you'll need to query each control using FindControl() then set properties
etc.
I have never seen a measurement of the difference in performance, but I
would be surprised to find there's much of a difference.
There are ItemCreated and ItemDataBound events that you can handle that let you programmatically catch each of the columns in the dg as they are bound
and assign data to them. It can be done, but using a template tag is often
more efficient and more self-explanatory.


The ItemCreated and ItemDataBound events are where I usually do things like
this. Each one fires once per item. I use ItemCreated for any code which
does not depend on the underlying data, and ItemDataBound for any code which
does depend on the underlying data.
--
John Saunders
johnwsaundersiii at hotmail
Nov 18 '05 #4
Thanks for the replies guys - Seems its a case of doing what feels right! :)

Simon.

"John Saunders" <jo**************@notcoldmail.com> wrote in message
news:eg**************@TK2MSFTNGP10.phx.gbl...
"Rick Strahl [MVP]" <ri********@hotmail.com> wrote in message
news:u4**************@TK2MSFTNGP11.phx.gbl...
Hi Simon,

I think using good judgement is more important than following 'rules' all the time. In some situations using script tags inside of the page is just plain easier to work with and provides better performance to boot.
In my experience, inline script tags can be more difficult to maintain

that codebehind.
You can access each element as it's loaded via code, but if you have a
template column this gets to be a hassle that is also pretty slow because you'll need to query each control using FindControl() then set properties etc.
I have never seen a measurement of the difference in performance, but I
would be surprised to find there's much of a difference.
There are ItemCreated and ItemDataBound events that you can handle that

let
you programmatically catch each of the columns in the dg as they are bound and assign data to them. It can be done, but using a template tag is often more efficient and more self-explanatory.


The ItemCreated and ItemDataBound events are where I usually do things

like this. Each one fires once per item. I use ItemCreated for any code which
does not depend on the underlying data, and ItemDataBound for any code which does depend on the underlying data.
--
John Saunders
johnwsaundersiii at hotmail

Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Pelle | last post by:
Hello all, I have to admit, that the idea that occurred to me recently is weird. It was somehow inspired by the huge response on the "delete operator" thread, but goes into a somewhat different...
18
by: deanbrown3d | last post by:
I mean, is this correct? try { Screen->Cursor = crHourglass; Do something bad return false; else return true; }
18
by: Adam Zimny | last post by:
This is fragment of code from Bruce Eckel's Thinking in c++ ( last 3 couts are mine to show what happened ). The question is: is Bruce Eckel wrong or g++ ( my version is 3.2.3 ) is buggy ? //:...
15
by: Jon Skeet | last post by:
I've been briefly musing on what is probably a pretty silly idea, but one which would no doubt benefit from being discussed and thoroughly shot down in flames rather than being allowed to fester in...
9
by: Alvin Bruney | last post by:
The more knowledgable I get about this .net world, the more questions I have. ..NET uses pass by reference for all objects....uhhh I mean pass by value. (Couldn't resist this jab) Consider a...
7
by: Homa | last post by:
Hi, I'm thinking what will happen if two users access a page at the same time. If there are any local variable in the page, will this cause concurrency problem? Simarily, if this page need to...
4
by: gopal | last post by:
Hi, i am now reading thru the thinking in C++ and i have some doubts at section CONST REFERENCES as The use of const references in function arguments is especially important because your...
1
by: Nemisis | last post by:
hi guys, Currently converting an old classic asp system to a OOP asp.net application. We are building the new application using a 3 tier arcitecture and i was wondering about the following. ...
2
by: ChrisM | last post by:
I've got a medium sized project written in C# for .NET1.1 the project is live, but still under constant development. There seems to be a lot of new stuff in .NET2.0 that I'm missing out on, and now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.