M
Martin Schmid
I am trying to implement a DataView for a DataGrid so I can sort at runtime
by clicking on column headers. My initial page load works... it displays
the data However, when I click a column heading at run time, the data
doesn't sort as expected, in fact, the DataGrid becomes empty, all I see are
column headings:
SqlConnection sqlConnection;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected ProjContMan.dsProjByDate dsProjByDate;
protected System.Data.DataView dataView;
SqlDataAdapter sqlDataAdapter;
private void Page_Load(object sender, System.EventArgs e)
{
sqlConnection = (SqlConnection)Session["sqlConnection"];
sqlDataAdapter = (SqlDataAdapter)Session["sqlDataAdapter"];
if(!IsPostBack)
{
sqlDataAdapter.Fill(dsProjByDate);
DataGrid1.DataSource=dataView;
DataGrid1.DataBind();
}
}
private void DataGrid1_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
dataView.Sort=e.SortExpression;
DataGrid1.DataBind();
}
by clicking on column headers. My initial page load works... it displays
the data However, when I click a column heading at run time, the data
doesn't sort as expected, in fact, the DataGrid becomes empty, all I see are
column headings:
SqlConnection sqlConnection;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected ProjContMan.dsProjByDate dsProjByDate;
protected System.Data.DataView dataView;
SqlDataAdapter sqlDataAdapter;
private void Page_Load(object sender, System.EventArgs e)
{
sqlConnection = (SqlConnection)Session["sqlConnection"];
sqlDataAdapter = (SqlDataAdapter)Session["sqlDataAdapter"];
if(!IsPostBack)
{
sqlDataAdapter.Fill(dsProjByDate);
DataGrid1.DataSource=dataView;
DataGrid1.DataBind();
}
}
private void DataGrid1_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
dataView.Sort=e.SortExpression;
DataGrid1.DataBind();
}