title: How to add values programmatically to a datalist/datasource in ASP.NET?
body: <p>I am in need of a method of adding values to a DataList that are not coming from the SQLDataSource that the DataList is connected to. These values are not necessarily found in my database but nonetheless need to show up in the DataList I already have.</p>
  
  <p>On my page I have this structure:</p>
  
  <pre><code>DataListA
      Hidden Field
      Label
      DataListB
      SQLDataSourceB
  
  SQLDataSourceA
  </code></pre>
  
  <p>I am looking for methods to programmatically add entries (custom ones at that) to SQLDataSourceB such that DataListB includes these extra rows I need displaying in DataListB. I've looked into the Pre_Render events and examples such as found <a href="https://stackoverflow.com/questions/6213777/add-rows-in-a-gridview-c-sharp">here</a> but I don't need to change entries, nor alter their style. I am looking for <strong>adding</strong> custom entries, is there a way to do this?</p>
  
  <hr>
  
  <p><strong>Edit:</strong> The results that DataListB is displaying is an "Department", "Code" and "Name". These are displaying school courses. Ie, a typical result would look like: <code>ART 3000 Photography</code>
  . Courses that I am looking to add to DataListB are custom courses that are in the same format as the above example. The reason behind this - if I display <code>ART 3000 Photography</code> in DataListB, I want to display <code>SCI 1000 Biology</code> rather than if I didn't display <code>ART 3000 Photography</code> , I would want <code>SCI 1100 Chemistry</code>. It is a multitude of cases such as this that I need to be able to check what courses I am displaying (before page load) and alter which custom classes I need to add to DataListB.</p>
  
  <p><strong>@ethorn10</strong> I have two primary needs of adding these custom courses to my DataList. The first case is for a range of classes. For every class displayed in the table within this range alters the x number of classes more that I need from this pool. For example let's say I have a range of classes with a "Code" from 1000 to 3000. The limit of classes within this range that should (at minimum) display in the table is 6. Thus, (and I realize a label of some sort, rather than an entry in the datalist is necessary for this) I want the user to see "6 more classes between 1000 to 3000". For every course in this range that is displayed, I want the "6" to decrement, thus if one class is taken in the range, the display/label should read "5 more classes between 1000 to 3000".</p>
  
  <p>The second case is similar to the first, but instead of being inclusive from 1000 to 3000, there are is a pool of distinct classes. Thus it changes to "You need 2 more classes from these classes: 1200, 1350, 2300, etc..."</p>