Note that there are some explanatory texts on larger screens.

plurals
  1. POHow should I bind fields from a datasource to a ListView control?
    primarykey
    data
    text
    <p>I have a ListView control which I used to populate using an ASP ObjectDataSource control. This worked fine.</p> <p>However, I wanted to implement a filter that showed items in the ListView that began with the letter A, B, C, etc. To do this, I removed the ObjectDataSource control and replaced it with some code in the Page_Load event allowing me greater control over what I was passing in as the data source, similar to this:</p> <pre><code>System.Diagnostics.Debug.Print("{0:HH:mm:ss} : GET DATA", DateTime.Now); List&lt;MyItem&gt; items = GetItems("A"); // Gets a list of items with a description that // begins with A MyListView.Datasource = items; System.Diagnostics.Debug.Print("{0:HH:mm:ss} : BIND DATA", DateTime.Now); MyListView.DataBind(); System.Diagnostics.Debug.Print("{0:HH:mm:ss} : DONE", DateTime.Now); </code></pre> <p>Output (times are representative of actual results):</p> <pre><code>16:00:00 : GET DATA 16:00:00 : BIND DATA 16:00:20 : DONE </code></pre> <p>Since doing this, it takes about 20 seconds to load the page in my browser, instead of around 1 second when I used the ObjectDataSource.</p> <p>To load the data into my ListView rows, I use the standard <code>&lt;%# Eval("Description") %&gt;</code> method. After some searching on SO and google, <a href="https://stackoverflow.com/questions/2522820/should-we-be-using-eval-or-the-databind-event/2522912#2522912">some people</a> seem to say that <code>Eval</code> is inefficient.</p> <p>Why does manual binding in the Page_Load event slow everything down? Is it because Eval is inefficient? How can I speed it up, and what is the correct way to do this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload