我運行此事件處理程序和方法進行梳理我的GridView控件,但最高審計機關,它是空:排序後GridView變爲NULL?
protected void OtherGridView_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable dtSortTable = gvMeldingen.DataSource as DataTable;
DataView dvSortedView = new DataView(dtSortTable);
dvSortedView.Sort = e.SortExpression + " " + getSortDirectionString(e.SortDirection);
gvMeldingen.DataSource = dvSortedView;
gvMeldingen.DataBind();
}
private string getSortDirectionString(SortDirection sortDirection)
{
string newSortDirection = String.Empty;
if (sortDirection == SortDirection.Ascending)
{
newSortDirection = "ASC";
}
else
{
newSortDirection = "DESC";
}
return newSortDirection;
}
請幫助我。先謝謝你!
這是我得到的錯誤:在使用DataView之前必須設置DataTable。
這凸顯:dvSortedView.Sort = e.SortExpression + " " + getSortDirectionString(e.SortDirection)
是dtSortaTable空每次設置DataSource?您能否在頁面的Load事件中發佈代碼? – Larry 2011-05-09 07:25:57
有沒有加載事件 – SamekaTV 2011-05-09 07:27:08
我得到這個錯誤:DataTable必須在使用DataView之前設置。 並突出顯示:dvSortedView.Sort = e.SortExpression +「」+ getSortDirectionString(e.SortDirection); – SamekaTV 2011-05-09 07:28:35