My recommendation is that you directly save the sql query in the List here is an example:
List<Object> objects = new List<Object>();
using (SqlConnection connection = new SqlConnection(connectionString))
{
using (SqlCommand command = new SqlCommand())
{
StringBuilder query = new StringBuilder();
command.CommandType = System.Data.CommandType.Text;
command.CommandText = query.ToString();
SqlDataReader reader = null;
command.Connection = connection;
connection.Open();
reader = command.ExecuteReader();
while (reader.Read())
{
Object obj= new Object();
if(reader["a"] != DBNULL.Value)
obj.a = reader["a"];
objects.Add(obj);
}
}
}
One way to sort the list is:
objects.Sort((x, y) => -1 * x.a.CompareTo(y.a));
-1 * does it in Descending to order ascending removes -1 *
Edit
From what I see I left the part of the presentation here is an example, you have to use AutoGenerrateColumns="False" and mount your own column structure with columns and BoundFields, as extra TemplateField that you can put whatever you want LinkButtons o Datas with% = Eval ()%
<asp:GridView ID="GridView1" Runat="server" AutoGenerateColumns="False"
BorderWidth="1px" BackColor="White" GridLines="Vertical"
CellPadding="4" BorderStyle="None" BorderColor="#DEDFDE" ForeColor="Black">
<FooterStyle BackColor="#CCCC99"></FooterStyle>
<PagerStyle ForeColor="Black" HorizontalAlign="Right"
BackColor="#F7F7DE"></PagerStyle>
<HeaderStyle ForeColor="White" Font-Bold="True"
BackColor="#6B696B"></HeaderStyle>
<AlternatingRowStyle BackColor="White"></AlternatingRowStyle>
<Columns>
<asp:BoundField HeaderText="Titulo a mostrar" DataField="nombre de la propiedad del objeto"
SortExpression="nombre de la propiedad"></asp:BoundField>
<asp:TemplateField HeaderText="Prueba">
<ItemTemplate>
<%# ComputeSeniorityLevel(DateTime.Now –
(DateTime)Eval("HireDate")) %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<SelectedRowStyle ForeColor="White" Font-Bold="True"
BackColor="#CE5D5A"></SelectedRowStyle>
<RowStyle BackColor="#F7F7DE"></RowStyle>
</asp:GridView>
here more information:
link
link
link
Everything that can be assigned from the aspx can be assigned from c # to windowsforms such that:
dgViewStudents.AutoGenerateColumns = false;
dgViewStudents.DataSource = bs;
DataGridViewColumn col = new DataGridViewTextBoxColumn();
col.DataPropertyName = "ID";
col.HeaderText = "ID Column";
col.Name = "foo";
dgViewStudents.Columns.Add(col);