469,272 Members | 1,448 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,272 developers. It's quick & easy.

Simple(?) DataView Question

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.DataGridSortCommandEvent Args e)
{
dataView.Sort=e.SortExpression;
DataGrid1.DataBind();
}


--
Thanks,
Martin Schmid, EIT, CCSA, MCDBA, MCSE
Nov 15 '05 #1
4 1374
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]
- mv*@spam.guard.caspershouse.com

"Martin Schmid" <ma**********@sbcglobal.net.nospam> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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.DataGridSortCommandEvent Args e)
{
dataView.Sort=e.SortExpression;
DataGrid1.DataBind();
}


--
Thanks,
Martin Schmid, EIT, CCSA, MCDBA, MCSE

Nov 15 '05 #2
EnableViewState for DataGrid1 is true, as is enableViewState for DOCUMENT.

--
Thanks,
Martin Schmid, EIT, CCSA, MCDBA, MCSE
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:O6**************@TK2MSFTNGP11.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Martin Schmid" <ma**********@sbcglobal.net.nospam> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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.DataGridSortCommandEvent Args e)
{
dataView.Sort=e.SortExpression;
DataGrid1.DataBind();
}


--
Thanks,
Martin Schmid, EIT, CCSA, MCDBA, MCSE


Nov 15 '05 #3
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]
- mv*@spam.guard.caspershouse.com

"Martin Schmid" <ma**********@sbcglobal.net.nospam> wrote in message
news:ea**************@TK2MSFTNGP10.phx.gbl...
EnableViewState for DataGrid1 is true, as is enableViewState for DOCUMENT.

--
Thanks,
Martin Schmid, EIT, CCSA, MCDBA, MCSE
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:O6**************@TK2MSFTNGP11.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Martin Schmid" <ma**********@sbcglobal.net.nospam> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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.DataGridSortCommandEvent Args e)
{
dataView.Sort=e.SortExpression;
DataGrid1.DataBind();
}


--
Thanks,
Martin Schmid, EIT, CCSA, MCDBA, MCSE



Nov 15 '05 #4
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.DataGridSortCommandEvent Args e)
{
dataView.Sort=e.SortExpression;
DataGrid1.DataBind();
}


--
Thanks,
Martin Schmid, EIT, CCSA, MCDBA, MCSE
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:uY**************@TK2MSFTNGP12.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Martin Schmid" <ma**********@sbcglobal.net.nospam> wrote in message
news:ea**************@TK2MSFTNGP10.phx.gbl...
EnableViewState for DataGrid1 is true, as is enableViewState for DOCUMENT.

--
Thanks,
Martin Schmid, EIT, CCSA, MCDBA, MCSE
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote

in
message news:O6**************@TK2MSFTNGP11.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Martin Schmid" <ma**********@sbcglobal.net.nospam> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
> 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.DataGridSortCommandEvent Args e)
> {
> dataView.Sort=e.SortExpression;
> DataGrid1.DataBind();
> }
>
>
>
>
> --
> Thanks,
> Martin Schmid, EIT, CCSA, MCDBA, MCSE
>
>



Nov 15 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Maciej Nadolski | last post: by
7 posts views Thread by gene.ellis | last post: by
2 posts views Thread by Kirk | last post: by
2 posts views Thread by Anurag | last post: by
3 posts views Thread by Peter | last post: by
7 posts views Thread by abcd | last post: by
2 posts views Thread by Allain B√łge | last post: by
17 posts views Thread by AlBen | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.