Simple(?) DataView Question

  • Thread starter Thread starter Martin Schmid
  • Start date Start date
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();
}
 
Martin,

Do you have the viewstate enabled on the page? If you do not, then the
data on the grid will not be post back to the page for repopulation (you are
filling the grid only when it is not a postback, so that is why the grid is
empty).

Hope this helps.
 
EnableViewState for DataGrid1 is true, as is enableViewState for DOCUMENT.

--
Thanks,
Martin Schmid, EIT, CCSA, MCDBA, MCSE
Nicholas Paldino said:
Martin,

Do you have the viewstate enabled on the page? If you do not, then the
data on the grid will not be post back to the page for repopulation (you are
filling the grid only when it is not a postback, so that is why the grid is
empty).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Martin Schmid said:
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();
}
 
Martin,

When you look at the page that is sent to the browser, do you see the
viewstate persisted to the page in a hidden form field?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Martin Schmid said:
EnableViewState for DataGrid1 is true, as is enableViewState for DOCUMENT.

--
Thanks,
Martin Schmid, EIT, CCSA, MCDBA, MCSE
message news:[email protected]...
Martin,

Do you have the viewstate enabled on the page? If you do not, then the
data on the grid will not be post back to the page for repopulation (you are
filling the grid only when it is not a postback, so that is why the grid is
empty).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Martin Schmid said:
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();
}
 
I have revised my code as follows... but I don't understand what is going on
yet. Do I have any redundancies ... any explanation is helpful!


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)
{
DataGrid1.DataSource=dataView;
}
sqlDataAdapter.Fill(dataView.Table);
DataGrid1.DataBind();
}


private void DataGrid1_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
dataView.Sort=e.SortExpression;
DataGrid1.DataBind();
}




--
Thanks,
Martin Schmid, EIT, CCSA, MCDBA, MCSE
Nicholas Paldino said:
Martin,

When you look at the page that is sent to the browser, do you see the
viewstate persisted to the page in a hidden form field?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Martin Schmid said:
EnableViewState for DataGrid1 is true, as is enableViewState for DOCUMENT.

--
Thanks,
Martin Schmid, EIT, CCSA, MCDBA, MCSE
message news:[email protected]...
Martin,

Do you have the viewstate enabled on the page? If you do not,
then
the
data on the grid will not be post back to the page for repopulation
(you
are
filling the grid only when it is not a postback, so that is why the
grid
is
empty).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

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();
}
 
Back
Top