title: sort a grid view based on forecolor of row
body: <p>I have a grid view.</p>
  
  <p>I am changing the color of certain rows to red in the gridview based on logic in the row command event.</p>
  
  <p>Now I would like to sort the grid view such that , the colored rows appear on the top of the grid view .
  Is there any way I can do that. ? I have my code below :</p>
  
  <p>aspx :</p>
  
  <pre><code>&lt;asp:GridView ID="gvMain" runat="server" ShowFooter="true"OnRowCommand="gvMain_RowCommand"&gt;
                                  &lt;Columns&gt;
                                   &lt;HeaderStyle Width="15%"&gt;&lt;/HeaderStyle&gt;
                                  &lt;/asp:TemplateField&gt;
                                  &lt;asp:TemplateField HeaderText="Std" SortExpression="Std" &gt;
                                      &lt;ItemTemplate&gt;
                    &lt;asp:Label ID="lblStd" runat="server" Text='&lt;%#Eval("Std") %&gt;'&gt;&lt;/asp:Label&gt;
                                      &lt;/ItemTemplate&gt;
                                      &lt;EditItemTemplate&gt;
          &lt;asp:DropDownList Width="200" runat="server"  id="cboStd" Font-Size="7pt" Height="12pt"&gt;
                                      &lt;/asp:DropDownList&gt;                                         
                                      &lt;/EditItemTemplate&gt;
                                  &lt;/asp:TemplateField&gt;
                     &lt;asp:TemplateField HeaderText="Dept" SortExpression="Dept" &gt;
                                      &lt;ItemTemplate&gt;
          &lt;asp:Label ID="lblDept" runat="server" Text='&lt;%#Eval("Dept") %&gt;'&gt;&lt;/asp:Label&gt;
                                      &lt;/ItemTemplate&gt;
                                      &lt;EditItemTemplate&gt;
        &lt;asp:DropDownList Width="100" runat="server"  id="cboDept" Font-Size="7pt" Height="12pt"&gt;
                                      &lt;/asp:DropDownList&gt;                                       
                                      &lt;/EditItemTemplate&gt;
                                      &lt;/asp:TemplateField&gt;
                                  &lt;/Columns&gt;
                                 &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>aspx.cs</p>
  
  <pre><code>protected void gvMain_RowDataBound(object sender, GridViewRowEventArgs e)
          {
              try
              {
                  List&lt;StdMap&gt; lstStd = null;
  
                  if (gvMain.EditIndex == e.Row.RowIndex)
                  {
                      lstStd = Service.GetDetails();
  
                  if (e.Row.RowType == DataControlRowType.DataRow)
                  {
                      lstStd = Service.GetDetails();                    
                      ReportMap row = ((ReportMap)e.Row.DataItem);
  
                      if ("condition to change color to red ")
                      {
                          e.Row.Cells[1].ForeColor = System.Drawing.Color.Red;
                      }
                      else
                      {
  
                      }
                      row = null;
                  }
  
              }
              catch (Exception ex)
              {
  
              }
          }
  </code></pre>
  
  <p>What should i do to have all the rows with forecolor red to appear on top of the grid view ?</p>