Ahoj,
Nejak nevim jak mam sortovat v GridView uz jsem zkousel plno veci a take google.. V gridview mam Jmeno, Prijmeni.. Zde mam kod
<asp:GridView ID="GridView1" AutoGenerateColumns="false" runat="server" OnRowDataBound="GridView1_RowDataBound" allowsorting="True" onsorting="OnSort">
<Columns>
<asp:BoundField DataField="Jmeno" HeaderText="Jmeno" SortExpression="Jmeno" />
<asp:BoundField DataField="Prijmeni" HeaderText="Prijmeni" SortExpression="Prijmeni" />
</Columns>
</asp:GridView>
protected void OnSort(object sender, GridViewSortEventArgs e)
{
if (e.SortDirection == SortDirection.Ascending)
SortGridView(e.SortExpression, SortDirection.Descending);
else
SortGridView(e.SortExpression, SortDirection.Ascending);
}
// Nevim zda je to vhodny zpusob..
private void SortGridView(string sortExpression, SortDirection direction)
{
DataTable dataTable = GridView1.DataSource as DataTable;
if (dataTable != null)
{
DataView dataView = new DataView(dataTable);
dataView.Sort = sortExpression + " " + direction;
GridView1.DataSource = dataView;
GridView1.DataBind();
}
}
Bozel mi GridView.DataSource vraci porad null .. Muzete mi prosim poradit jak dosahnout toho sortovani?
Dekuji