title: Cannot sort DDL using multiple fields in asp.net
body: <p>I am trying to sort a dynamically created DDL.  This DDL has a combination of fields being Location1, Location2, Location3.</p>
  
  <p>The code used to create the DDL is as follows:</p>
  
  <pre><code>        ddlLocation.Items.Clear();
          dtLocation = dataSource.GetFilteredRiskInfo("location");
          ddlLocation.Items.Insert(0, new ListItem("All", "-1"));
          foreach (DataRow row in dtLocation.Rows)
          {
              if (this.ddlLocation.Items.FindByText(row["Location1"].ToString()) == null)
                  this.ddlLocation.Items.Add(new ListItem(row["Location1"].ToString()));
              if (this.ddlLocation.Items.FindByText(row["Location2"].ToString()) == null)
                  this.ddlLocation.Items.Add(new ListItem(row["Location2"].ToString()));
              if (this.ddlLocation.Items.FindByText(row["Location3"].ToString()) == null)
                  this.ddlLocation.Items.Add(new ListItem(row["Location3"].ToString()));
          }
  </code></pre>
  
  <p>The following code works for location1 (I think).</p>
  
  <pre><code>[DisplayColumn("location","Location1")]
  public partial class Location
  {
  }
  </code></pre>
  
  <p>I have been researching how to add multiple fields ie: location2 &amp; location3, it does not work.  The code itself shows an error for Location1 &amp; Location2 ("The name 'Location1' does not exist in the current context")</p>
  
  <pre><code>    [DisplayColumn("location","SortColumn")]
  public partial class Location
  {
      public string SortColumn
      {
          get { return Location1 + Location2; }
      }
  }
  </code></pre>
  
  <p>All help will be much apprecaited.</p>
  
  <p>The list of locations need to be as follows.  Say the locations have the following data.</p>
  
  <p>Location1:
  Sydney, Wollongong Perth</p>
  
  <p>Location2:
  Adelaide, Northern Territory</p>
  
  <p>Location3:
  Brisbane, Canberra, Hobart</p>
  
  <p>I need the combined list to look as follows:
  Adelaide
  Brisbane
  Canberra
  Hobart
  Northern Territory
  Perth
  Sydney
  Wollongong</p>
  
  <p>My code now looks as follows:</p>
  
  <pre><code>            ddlLocation.Items.Clear();
          // new table to combine the 3 columns of dtLocation into a one column datatable
          DataTable sortedDt = new DataTable();
          dtLocation = dataSource.GetFilteredRiskInfo("location");
          sortedDt.Columns.Add("Location");
  
          // combining columns
          foreach (DataRow row in dtLocation.Rows)
          {
              sortedDt.Rows.Add(row["Location1"]);
              sortedDt.Rows.Add(row["Location2"]);
              sortedDt.Rows.Add(row["Location3"]);
          }
  
          // now sort these now that they're all in the same column
          sortedDt.DefaultView.Sort = "Location";
          sortedDt = sortedDt.DefaultView.ToTable(); // should be the new sorted table
  
          // now your original code, but modified to populate the ddl with the new sorted data
  
  
          ddlLocation.Items.Insert(0, new ListItem("All", "-1"));
          foreach (DataRow row in sortedDt.Rows)
          {
              this.ddlLocation.Items.Add(new ListItem(row["Location"].ToString()));
          }
  </code></pre>
  
  <p>Now the list is in alphabetical order but has duplicate entries.  I need to be able to remove the duplicates/make the entries distinct.</p>