Thinking the right way?

Discussion in 'ASP .Net' started by Simon Harris, May 31, 2004.

  1. Simon Harris

    Simon Harris Guest

    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!
     
    Simon Harris, May 31, 2004
    #1
    1. Advertising

  2. Simon Harris

    clintonG Guest

    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" <> wrote in message
    news:...
    > 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!
    >
    >
     
    clintonG, May 31, 2004
    #2
    1. Advertising

  3. 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" <> wrote in message
    news:...
    > 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!
    >
    >
     
    Rick Strahl [MVP], May 31, 2004
    #3
  4. "Rick Strahl [MVP]" <> wrote in message
    news:...
    > 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
     
    John Saunders, Jun 1, 2004
    #4
  5. Simon Harris

    Simon Harris Guest

    Thanks for the replies guys - Seems its a case of doing what feels right! :)

    Simon.

    "John Saunders" <> wrote in message
    news:...
    > "Rick Strahl [MVP]" <> wrote in message
    > news:...
    > > 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
    >
    >
     
    Simon Harris, Jun 2, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tom
    Replies:
    0
    Views:
    447
  2. Rizwan

    Thinking the right solution

    Rizwan, Jan 6, 2005, in forum: Java
    Replies:
    0
    Views:
    312
    Rizwan
    Jan 6, 2005
  3. Replies:
    18
    Views:
    625
    Ioannis Vranos
    Mar 6, 2005
  4. Simon Harris

    Thinking in the right way?

    Simon Harris, May 31, 2004, in forum: ASP General
    Replies:
    4
    Views:
    147
  5. optimistx

    Linear thinking vs essential thinking

    optimistx, Oct 28, 2009, in forum: Javascript
    Replies:
    4
    Views:
    196
    Dr J R Stockton
    Oct 29, 2009
Loading...

Share This Page