Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. proper use of repeater control question

proper use of repeater control question

Scheduled Pinned Locked Moved ASP.NET
databasequestionwpfwcfhelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    icewolf_snowfire
    wrote on last edited by
    #1

    Hi, I'm hoping you guys can help me with a question. I've been reviewing someone else's code, and I found that in some places where they are using a repeater to display data from a database, in places where the Database query will only ever return 1 row of data. They are returning a reader, loading a datatable with the reader data, and binding that datatable to a repeater. now am I nutz, or is that extremely inefficient? it's always been my practice to take the reader, check for rows, and then set individual controls (like literals) to the fields directly. the only reason I can think of to do this, is that if for some reason there isn't any data, the repeater won't display anything. however I've always handled this by wrapping the results in a div, and setting the div's visibility property to false if there is no data returned. please let me know your opinion. thank you

    T 1 Reply Last reply
    0
    • I icewolf_snowfire

      Hi, I'm hoping you guys can help me with a question. I've been reviewing someone else's code, and I found that in some places where they are using a repeater to display data from a database, in places where the Database query will only ever return 1 row of data. They are returning a reader, loading a datatable with the reader data, and binding that datatable to a repeater. now am I nutz, or is that extremely inefficient? it's always been my practice to take the reader, check for rows, and then set individual controls (like literals) to the fields directly. the only reason I can think of to do this, is that if for some reason there isn't any data, the repeater won't display anything. however I've always handled this by wrapping the results in a div, and setting the div's visibility property to false if there is no data returned. please let me know your opinion. thank you

      T Offline
      T Offline
      ToddHileHoffer
      wrote on last edited by
      #2

      There are better ways of the doing that, but it probably doesn't matter. As you say you can always count the rows in the data table. If no rows exists display another div. If this application is going to have 10K+ users then you might want to look at doing this in a more efficient way. But really it is probably fine. However, you really should not use a repeater if you are only going to have one record. That's just common sense, it is called a repeater for a reason. Also, why use a datareader to get a datatable. This is foolish. Use the dataAdapter to get a dataTable. Use DataReader to iterate through read only data or bind a control directly to a datareader object.

      I didn't get any requirements for the signature

      I 1 Reply Last reply
      0
      • T ToddHileHoffer

        There are better ways of the doing that, but it probably doesn't matter. As you say you can always count the rows in the data table. If no rows exists display another div. If this application is going to have 10K+ users then you might want to look at doing this in a more efficient way. But really it is probably fine. However, you really should not use a repeater if you are only going to have one record. That's just common sense, it is called a repeater for a reason. Also, why use a datareader to get a datatable. This is foolish. Use the dataAdapter to get a dataTable. Use DataReader to iterate through read only data or bind a control directly to a datareader object.

        I didn't get any requirements for the signature

        I Offline
        I Offline
        icewolf_snowfire
        wrote on last edited by
        #3

        Thanks Todd you mentioned a better way? do you mean a better way than binding the reader data to literals? if so, would you mind giving more details? This particular page get's 4-5k views daily, and will see more as the application gets expanded, and marketed more, so I will be re-writing this page at least. I have no idea why they are retrieving the data like that, my guess is the person who wrote it didn't know any other way of binding data than by using a datatable. I have a feeling I'm going to find lots more WTF's when I get the final codeset and can look at everything together.

        T 1 Reply Last reply
        0
        • I icewolf_snowfire

          Thanks Todd you mentioned a better way? do you mean a better way than binding the reader data to literals? if so, would you mind giving more details? This particular page get's 4-5k views daily, and will see more as the application gets expanded, and marketed more, so I will be re-writing this page at least. I have no idea why they are retrieving the data like that, my guess is the person who wrote it didn't know any other way of binding data than by using a datatable. I have a feeling I'm going to find lots more WTF's when I get the final codeset and can look at everything together.

          T Offline
          T Offline
          ToddHileHoffer
          wrote on last edited by
          #4

          icewolf_snowfire wrote:

          do you mean a better way than binding the reader data to literals? if so, would you mind giving more details?

          Yes I did. It depends on your individual situation, but if you are only viewing one record I wouldn't use any databinding. Just put the controls you need inside a div tag. Write an init method to load the data (obviously only during the initial load and not postbacks). If the data is constantly changing then use a dataReader or output parameters in a stored procedure. If the data is rather static then cache the data. I wrote a sample article about how to do that here[^] Also, check this out http://msdn.microsoft.com/en-us/library/ms998549.aspx[^]

          I didn't get any requirements for the signature

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups