Sorting a ListBox bound to an ObjectDataSource using a dropdown with 2 selections
<p>I am having an issue on Sorting a ListBox with a dropdown.  The dropdown will have 2 options:</p>

<ol>
<li><p>Sort By #</p></li>
<li><p>Sort By Type</p></li>
</ol>

<p>The ListBox contains a list of items which are initially ordered in ascending order by #.  It has the following format:</p>

<ol>
<li>1: Red</li>
<li>2: Green</li>
<li>3: Blue</li>
<li>4: Red</li>
<li>5: Red</li>
</ol>

<p>If the user choses Sort By #, it should sort in descending order if it is already in ascending order and if in ascending order if it is in descending order.  If the user choses Sort By Type, it should order the colors, then #, so the above list becomes:</p>

<ol>
<li>1: Red</li>
<li>4: Red</li>
<li>5: Red</li>
<li>2: Green</li>
<li>3: Blue</li>
</ol>

<p>The lisbox is gets its data from an ObjectDataSource which is defined as follows:</p>

<pre><code>&lt;asp:ObjectDataSource ID="odsColors" runat="server" SelectMethod="GetColors"
        TypeName="XaiSoft.Data"&gt;  
&lt;/asp:ObjectDataSource&gt;
</code></pre>

<p>I have stubbed out a method for sorting, but this is where I am stuck at, I am not sure about how to do it:</p>

<pre><code>public void SortColorList()
{

}
</code></pre>

<p>I updated the above method to show what I am going for, but I am getting the following error:</p>

<p>Both DataSource and DataSourceID are defined on 'lstColors'.  Remove one definition.</p>

<pre><code>protected void SortColorList()
{

    XaiSoft.Data.Colors c = new XaiSoft.Data.Colors();
    DataTable dt = c.GetColorList();
    DataView dv = new DataView(dt);

    dv.Sort = "[" + dv.Table.Columns["ColorName"].ColumnName + "] asc";
    lstAuctions.DataSource = dv; //Error happens here.
    lstAuctions.DataBind();
</code></pre>

<p>}</p>

<p>I got around the error, by setting the DataSourceId = string.empty;</p>

<p>Thanks for the help,
XaiSoft</p>
