Hi there
I'm trying to add in sorting for the data grid in my web page but nothing happens when I click on the table headers.
I've researched the web and developed the code below and set AllowSorting to true in the Properties box in Visual Studio. I've also tried debugging this and setting a breakpoint but the method is never hit.
Should I need to call something from my OnPreRender or another part of the ASP.LifeCycle?
I'm trying to add in sorting for the data grid in my web page but nothing happens when I click on the table headers.
I've researched the web and developed the code below and set AllowSorting to true in the Properties box in Visual Studio. I've also tried debugging this and setting a breakpoint but the method is never hit.
Should I need to call something from my OnPreRender or another part of the ASP.LifeCycle?
Code:
protected void contactsGrid_SortCommand(object source, DataGridSortCommandEventArgs e)
{
DataTable dt = WebStaffManager.Instance.SearchDefault(FirstNameBox.Text,
SurnameBox.Text, PhoneBox.Text);
DataView dv = new DataView(dt);
dv.AllowNew = false;
dv.AllowDelete = false;
dv.AllowEdit = false;
dv.Sort = ViewState["sorting"].ToString();
if ((ViewState.Count % 2) == 0)
{
dv.Sort = e.SortExpression + " " + "ASC";
}
else
{
dv.Sort = e.SortExpression + " " + "DESC";
}
ViewState["sorting"] = dv.Sort;
contactsGrid.DataSource = dv;
contactsGrid.DataBind();
}
Comment