Problem Sorting a DataGrid

S

Steve Evans

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,076
Latest member
OrderKetoBeez

Latest Threads

Top