안녕 얘들 아 Allowporting = "True"로 설정하여 내 ASP 그리드 정렬 싶었어요. 또한 이벤트에 코드를 추가했지만 작동하지 않는 것 같습니다.GridView ASP 그리드에서 정렬
private void PopulateGridView()
{
var a = from c in sample_worker.get()
select new
{
c.CemID,
c.Title,
c.Description
};
grd_sample.DataSource = a;
grd_sample.DataBind();
}
이것은 그리드를 채우는 코드입니다. 나는 있습니다 ..!의 IsPostBack을 아래이 추가
정렬 코드 ...
private string ConvertSortDirectionToSql(SortDirection sortDirection)
{
string newSortDirection = String.Empty;
switch (sortDirection)
{
case SortDirection.Ascending:
newSortDirection = "ASC";
break;
case SortDirection.Descending:
newSortDirection = "DESC";
break;
}
return newSortDirection;
}
protected void grd_sample_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable dataTable = grd_sample.DataSource as DataTable;
if (dataTable != null)
{
DataView dataView = new DataView(dataTable);
dataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e.SortDirection);
grd_sample.DataSource = dataView;
grd_sample.DataBind();
}
}
내가이 ... 또한 내가 앞뒤로 정렬 할 수있을 것입니다 해결하기 위해 무엇을 할 수 있는가? desc - asc - desc. 또한 if (dataTable! = null)은 항상 null입니다. 사전에
감사
고마워요. 당신의 코드를 시험해 보았습니다. 그러나 나는 한 줄을 바꿔야했다. if (e.SortDirection.ToString() == "Ascending") .. 다시 한번 고마워요! – anonymous1110