D
David
Hi all,
I am using asp.net and c# and linq to sql.
I have...
private void BuildHistory()
{
using (coDataClassesDataContext dc = new coDataClassesDataContext())
{
var TrailerHistory = from th in dc.TrailerHistories.Where(a =>
a.TrailerID == FleetIDEdit.Text)
orderby th.DateOfRepair descending
select th;
HistoryGridView.DataSource = TrailerHistory;
HistoryGridView.DataBind();
}
}
then I want to sort the gridview by clicking a column title, so I have...
protected void HistoryGridView_Sorting(object sender,
GridViewSortEventArgs e)
{
DataTable dataTable = HistoryGridView.DataSource as DataTable;
if (dataTable != null)
{
DataView dataView = new DataView(dataTable);
dataView.Sort = e.SortExpression + " " +
ConvertSortDirectionToSql(e.SortDirection);
HistoryGridView.DataSource = dataView;
HistoryGridView.DataBind();
}
}
The problem is that dataTable is null.
Stepping through, it tells when I hover over the .DataSource
"Cannot access a disposed object.\r\nObject name: 'DataContext accessed
after Dispose.'."
which is sort of obvious, but it doesn't really tell me enough information
that I can fix it.
Should I basically have my whole linq inside the Sorting function? If so,
how do i then build my orderby clause?
Thanks.
--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
I am using asp.net and c# and linq to sql.
I have...
private void BuildHistory()
{
using (coDataClassesDataContext dc = new coDataClassesDataContext())
{
var TrailerHistory = from th in dc.TrailerHistories.Where(a =>
a.TrailerID == FleetIDEdit.Text)
orderby th.DateOfRepair descending
select th;
HistoryGridView.DataSource = TrailerHistory;
HistoryGridView.DataBind();
}
}
then I want to sort the gridview by clicking a column title, so I have...
protected void HistoryGridView_Sorting(object sender,
GridViewSortEventArgs e)
{
DataTable dataTable = HistoryGridView.DataSource as DataTable;
if (dataTable != null)
{
DataView dataView = new DataView(dataTable);
dataView.Sort = e.SortExpression + " " +
ConvertSortDirectionToSql(e.SortDirection);
HistoryGridView.DataSource = dataView;
HistoryGridView.DataBind();
}
}
The problem is that dataTable is null.
Stepping through, it tells when I hover over the .DataSource
"Cannot access a disposed object.\r\nObject name: 'DataContext accessed
after Dispose.'."
which is sort of obvious, but it doesn't really tell me enough information
that I can fix it.
Should I basically have my whole linq inside the Sorting function? If so,
how do i then build my orderby clause?
Thanks.
--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available