I'm setting up a datagrid and am trying to sort it using what is
essentially code taken straight from the .NET framework documentation.
I used Visual Studio to build the data source itself, which I fill and
bind in Page_Load.
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
sdaHIMS.Fill(dsHIMS);
dgLeases.DataBind();
Session["Source"] = dsHIMS.Tables[0];
}
}
Okay so far, the datagrid populates. AllowSorting is true and I have
Sort_Click defined to handle sorting:
private void Sort_Click(object s, DataGridSortCommandEventArgs e)
{
DataTable dt = (DataTable)Session["Source"];
DataView dv = new DataView(dt);
dv.Sort = e.SortExpression;
dgLeases.DataSource = dv;
dgLeases.DataBind();
}
That's almost exactly what's in the documentation. On the databind,
however, I get nothing but the datagrid's headers--no data appears.
I've added debug lines to Sort_Click, checking dv.Table.TableName,
dv.Table.Rows.Count, etc. They show that the table and its data are
there, but I lose it all on the databind. Does anyone know what's
happening?
Thanks, Steve