I had something like the following working:
!!!!!!!!!! !!!!!!!!!! Start of Code snipet!!!!!!!!!! !!!!!!!!!!
<asp:DataGrid id="FormListDataGrid" runat="server"
AutoGenerateColumns="False" ShowHeader="true" HeaderStyle-CssClass="header"
AllowSorting="true" OnSortCommand="SortCurrentMonth_OnClick"
HeaderStyle-Height="25px">
<Columns>
<asp:HyperLinkColumn Runat="server" DataNavigateUrlField="FormName"
DataNavigateUrlFormatString="ShowForm.aspx?form={0}" DataTextField="FormName"
HeaderText="Form Name" SortExpression="FormName"></asp:HyperLinkColumn>
<asp:BoundColumn DataField="Due Date" HeaderText="Due Date"
DataFormatString="{0:d}" SortExpression="Due Date"/>
<asp:BoundColumn DataField="Entity" HeaderText="Entity"
SortExpression="Entity" />
</Columns>
</asp:DataGrid>

protected void SortCurrentMonth_OnClick(Object source,
DataGridSortCommandEventArgs e)
{
((DataView) FormListDataGrid.DataSource).Sort= e.SortExpression;
FormListDataGrid.DataBind();
}
!!!!!!!!!! !!!!!!!!!! End of Code snipet!!!!!!!!!! !!!!!!!!!!

This aspx load up the DataGrid on page start up.

However, I now created another ASPX for reporting, whose DataGrid is set to
Visible=false initially, with the DataSource, etc. only set at the click of a
button. Code-snippet as follows:

~~~~~~~~~~~~~~~Start of new Code snippet~~~~~~~~~~~~~~~
<asp:DataGrid id="ReportDataGrid" runat="server"
AutoGenerateColumns="False" ShowHeader="true"
HeaderStyle-CssClass="header" AllowSorting="true"
OnSortCommand="SortReport_OnClick" HeaderStyle-Height="25px" CellSpacing="5">
<Columns>
<asp:HyperLinkColumn Runat="server" DataNavigateUrlField="FormName"
DataNavigateUrlFormatString="ShowForm.aspx?form={0}" DataTextField="FormName"
HeaderText="Form Name" SortExpression="FormName"></asp:HyperLinkColumn>
<asp:BoundColumn runat="server" DataField="Due Date" HeaderText="Due
Date" DataFormatString="{0:d}"
SortExpression="Due Date" />

<asp:BoundColumn runat="server" DataField="Manager" HeaderText="Last
Manager" SortExpression="Manager" />
<asp:BoundColumn runat="server" DataField="DummyComments"
HeaderText="Dummy Comments" />
<asp:BoundColumn runat="server" DataField="Status" HeaderText="Status"
SortExpression="Status"/>
</Columns>
</asp:DataGrid>

private void ReportButton_Click(object sender, System.EventArgs e)
{
string reportSQL = "SELECT * FROM forms";
//Render reportSQL now based upon selected criteria on the web form
DataSet dataList = new DataSet();

OdbcConnection Conn = new OdbcConnection("Driver={Microsoft Access Driver
(*.mdb)};DBQ=c:\\dev\\outstandingForms.mdb");

Conn.Open();
OdbcDataAdapter accessDataAdapter = new OdbcDataAdapter(reportSQL,Conn);
accessDataAdapter.Fill(dataList);

DataView oView= new DataView(dataList.Tables[0]);
ReportDataGrid.DataSource= oView;
ReportDataGrid.DataBind();
Conn.Close();
ReportDataGrid.Visible= true;

}


protected void SortReport_OnClick(Object source,
DataGridSortCommandEventArgs e)
{
((DataView) ReportDataGrid.DataSource).Sort= e.SortExpression;
ReportDataGrid.DataBind();
}
~~~~~~~~~~~~~~~End of new Code snippet~~~~~~~~~~~~~~~

The issue now is whenever I try to sort something by clicking on the column
heading, I get an error, which is caused by an un-initialised
ReportDataGrid.DataSource! How could I rectify this? I don't really want to
re-run the query and re-set the DataSource, re-create the SQL everytime, do I?


"Kevin Yu [MSFT]" wrote:

> Hi Patrick,
>
> I agree with Elton that you have to assign e.SortExpression to the sort
> expression of the DataView.
>
> oView.Sort = e.SortExpression;
>
> Here is an example:
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
> frlrfsystemwebuiwebcontrolsdatagridsortcommandeventargsclasssortexpressionto
> pic.asp
>
> Kevin Yu
> =======
> "This posting is provided "AS IS" with no warranties, and confers no
> rights."
>
>

RE: DataGrid.DataSource undefined when trying to Sort by EltonW

EltonW
Thu May 26 12:21:02 CDT 2005

In fact, datagridâ??s data source will loss when it posts back. You need to
rebind the datagridâ??s data source. You donâ??t need to re-query data from DB.
You can save data source object in Session or Context. Then retrieve it when
needed.

HTH

Elton Wang

"Patrick" wrote:

> I had something like the following working:
> !!!!!!!!!! !!!!!!!!!! Start of Code snipet!!!!!!!!!! !!!!!!!!!!
> <asp:DataGrid id="FormListDataGrid" runat="server"
> AutoGenerateColumns="False" ShowHeader="true" HeaderStyle-CssClass="header"
> AllowSorting="true" OnSortCommand="SortCurrentMonth_OnClick"
> HeaderStyle-Height="25px">
> <Columns>
> <asp:HyperLinkColumn Runat="server" DataNavigateUrlField="FormName"
> DataNavigateUrlFormatString="ShowForm.aspx?form={0}" DataTextField="FormName"
> HeaderText="Form Name" SortExpression="FormName"></asp:HyperLinkColumn>
> <asp:BoundColumn DataField="Due Date" HeaderText="Due Date"
> DataFormatString="{0:d}" SortExpression="Due Date"/>
> <asp:BoundColumn DataField="Entity" HeaderText="Entity"
> SortExpression="Entity" />
> </Columns>
> </asp:DataGrid>
>
> protected void SortCurrentMonth_OnClick(Object source,
> DataGridSortCommandEventArgs e)
> {
> ((DataView) FormListDataGrid.DataSource).Sort= e.SortExpression;
> FormListDataGrid.DataBind();
> }
> !!!!!!!!!! !!!!!!!!!! End of Code snipet!!!!!!!!!! !!!!!!!!!!
>
> This aspx load up the DataGrid on page start up.
>
> However, I now created another ASPX for reporting, whose DataGrid is set to
> Visible=false initially, with the DataSource, etc. only set at the click of a
> button. Code-snippet as follows:
>
> ~~~~~~~~~~~~~~~Start of new Code snippet~~~~~~~~~~~~~~~
> <asp:DataGrid id="ReportDataGrid" runat="server"
> AutoGenerateColumns="False" ShowHeader="true"
> HeaderStyle-CssClass="header" AllowSorting="true"
> OnSortCommand="SortReport_OnClick" HeaderStyle-Height="25px" CellSpacing="5">
> <Columns>
> <asp:HyperLinkColumn Runat="server" DataNavigateUrlField="FormName"
> DataNavigateUrlFormatString="ShowForm.aspx?form={0}" DataTextField="FormName"
> HeaderText="Form Name" SortExpression="FormName"></asp:HyperLinkColumn>
> <asp:BoundColumn runat="server" DataField="Due Date" HeaderText="Due
> Date" DataFormatString="{0:d}"
> SortExpression="Due Date" />
>
> <asp:BoundColumn runat="server" DataField="Manager" HeaderText="Last
> Manager" SortExpression="Manager" />
> <asp:BoundColumn runat="server" DataField="DummyComments"
> HeaderText="Dummy Comments" />
> <asp:BoundColumn runat="server" DataField="Status" HeaderText="Status"
> SortExpression="Status"/>
> </Columns>
> </asp:DataGrid>
>
> private void ReportButton_Click(object sender, System.EventArgs e)
> {
> string reportSQL = "SELECT * FROM forms";
> //Render reportSQL now based upon selected criteria on the web form
> DataSet dataList = new DataSet();
>
> OdbcConnection Conn = new OdbcConnection("Driver={Microsoft Access Driver
> (*.mdb)};DBQ=c:\\dev\\outstandingForms.mdb");
>
> Conn.Open();
> OdbcDataAdapter accessDataAdapter = new OdbcDataAdapter(reportSQL,Conn);
> accessDataAdapter.Fill(dataList);
>
> DataView oView= new DataView(dataList.Tables[0]);
> ReportDataGrid.DataSource= oView;
> ReportDataGrid.DataBind();
> Conn.Close();
> ReportDataGrid.Visible= true;
>
> }
>
>
> protected void SortReport_OnClick(Object source,
> DataGridSortCommandEventArgs e)
> {
> ((DataView) ReportDataGrid.DataSource).Sort= e.SortExpression;
> ReportDataGrid.DataBind();
> }
> ~~~~~~~~~~~~~~~End of new Code snippet~~~~~~~~~~~~~~~
>
> The issue now is whenever I try to sort something by clicking on the column
> heading, I get an error, which is caused by an un-initialised
> ReportDataGrid.DataSource! How could I rectify this? I don't really want to
> re-run the query and re-set the DataSource, re-create the SQL everytime, do I?
>
>
> "Kevin Yu [MSFT]" wrote:
>
> > Hi Patrick,
> >
> > I agree with Elton that you have to assign e.SortExpression to the sort
> > expression of the DataView.
> >
> > oView.Sort = e.SortExpression;
> >
> > Here is an example:
> >
> > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
> > frlrfsystemwebuiwebcontrolsdatagridsortcommandeventargsclasssortexpressionto
> > pic.asp
> >
> > Kevin Yu
> > =======
> > "This posting is provided "AS IS" with no warranties, and confers no
> > rights."
> >
> >

RE: DataGrid.DataSource undefined when trying to Sort by questions

questions
Fri May 27 04:11:03 CDT 2005

Any disadvantage of storing (a big) DataView in Session??

I never heard of storing data in System.Web.HttpContext.Current? How does
that work? Any disavantage over storing data in Session?

"Elton W" wrote:

> In fact, datagridâ??s data source will loss when it posts back. You need to
> rebind the datagridâ??s data source. You donâ??t need to re-query data from DB.
> You can save data source object in Session or Context. Then retrieve it when
> needed.
>
> HTH
>
> Elton Wang
>
> "Patrick" wrote:
>
> > I had something like the following working:
> > !!!!!!!!!! !!!!!!!!!! Start of Code snipet!!!!!!!!!! !!!!!!!!!!
> > <asp:DataGrid id="FormListDataGrid" runat="server"
> > AutoGenerateColumns="False" ShowHeader="true" HeaderStyle-CssClass="header"
> > AllowSorting="true" OnSortCommand="SortCurrentMonth_OnClick"
> > HeaderStyle-Height="25px">
> > <Columns>
> > <asp:HyperLinkColumn Runat="server" DataNavigateUrlField="FormName"
> > DataNavigateUrlFormatString="ShowForm.aspx?form={0}" DataTextField="FormName"
> > HeaderText="Form Name" SortExpression="FormName"></asp:HyperLinkColumn>
> > <asp:BoundColumn DataField="Due Date" HeaderText="Due Date"
> > DataFormatString="{0:d}" SortExpression="Due Date"/>
> > <asp:BoundColumn DataField="Entity" HeaderText="Entity"
> > SortExpression="Entity" />
> > </Columns>
> > </asp:DataGrid>
> >
> > protected void SortCurrentMonth_OnClick(Object source,
> > DataGridSortCommandEventArgs e)
> > {
> > ((DataView) FormListDataGrid.DataSource).Sort= e.SortExpression;
> > FormListDataGrid.DataBind();
> > }
> > !!!!!!!!!! !!!!!!!!!! End of Code snipet!!!!!!!!!! !!!!!!!!!!
> >
> > This aspx load up the DataGrid on page start up.
> >
> > However, I now created another ASPX for reporting, whose DataGrid is set to
> > Visible=false initially, with the DataSource, etc. only set at the click of a
> > button. Code-snippet as follows:
> >
> > ~~~~~~~~~~~~~~~Start of new Code snippet~~~~~~~~~~~~~~~
> > <asp:DataGrid id="ReportDataGrid" runat="server"
> > AutoGenerateColumns="False" ShowHeader="true"
> > HeaderStyle-CssClass="header" AllowSorting="true"
> > OnSortCommand="SortReport_OnClick" HeaderStyle-Height="25px" CellSpacing="5">
> > <Columns>
> > <asp:HyperLinkColumn Runat="server" DataNavigateUrlField="FormName"
> > DataNavigateUrlFormatString="ShowForm.aspx?form={0}" DataTextField="FormName"
> > HeaderText="Form Name" SortExpression="FormName"></asp:HyperLinkColumn>
> > <asp:BoundColumn runat="server" DataField="Due Date" HeaderText="Due
> > Date" DataFormatString="{0:d}"
> > SortExpression="Due Date" />
> >
> > <asp:BoundColumn runat="server" DataField="Manager" HeaderText="Last
> > Manager" SortExpression="Manager" />
> > <asp:BoundColumn runat="server" DataField="DummyComments"
> > HeaderText="Dummy Comments" />
> > <asp:BoundColumn runat="server" DataField="Status" HeaderText="Status"
> > SortExpression="Status"/>
> > </Columns>
> > </asp:DataGrid>
> >
> > private void ReportButton_Click(object sender, System.EventArgs e)
> > {
> > string reportSQL = "SELECT * FROM forms";
> > //Render reportSQL now based upon selected criteria on the web form
> > DataSet dataList = new DataSet();
> >
> > OdbcConnection Conn = new OdbcConnection("Driver={Microsoft Access Driver
> > (*.mdb)};DBQ=c:\\dev\\outstandingForms.mdb");
> >
> > Conn.Open();
> > OdbcDataAdapter accessDataAdapter = new OdbcDataAdapter(reportSQL,Conn);
> > accessDataAdapter.Fill(dataList);
> >
> > DataView oView= new DataView(dataList.Tables[0]);
> > ReportDataGrid.DataSource= oView;
> > ReportDataGrid.DataBind();
> > Conn.Close();
> > ReportDataGrid.Visible= true;
> >
> > }
> >
> >
> > protected void SortReport_OnClick(Object source,
> > DataGridSortCommandEventArgs e)
> > {
> > ((DataView) ReportDataGrid.DataSource).Sort= e.SortExpression;
> > ReportDataGrid.DataBind();
> > }
> > ~~~~~~~~~~~~~~~End of new Code snippet~~~~~~~~~~~~~~~
> >
> > The issue now is whenever I try to sort something by clicking on the column
> > heading, I get an error, which is caused by an un-initialised
> > ReportDataGrid.DataSource! How could I rectify this? I don't really want to
> > re-run the query and re-set the DataSource, re-create the SQL everytime, do I?
> >
> >
> > "Kevin Yu [MSFT]" wrote:
> >
> > > Hi Patrick,
> > >
> > > I agree with Elton that you have to assign e.SortExpression to the sort
> > > expression of the DataView.
> > >
> > > oView.Sort = e.SortExpression;
> > >
> > > Here is an example:
> > >
> > > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
> > > frlrfsystemwebuiwebcontrolsdatagridsortcommandeventargsclasssortexpressionto
> > > pic.asp
> > >
> > > Kevin Yu
> > > =======
> > > "This posting is provided "AS IS" with no warranties, and confers no
> > > rights."
> > >
> > >

RE: DataGrid.DataSource undefined when trying to Sort by EltonW

EltonW
Fri May 27 08:16:06 CDT 2005

Advantage of using session is improving performance. It reduces DB query over
networking. The disadvantage is that it consumes Web server memory resource.

Elton Wang

"Patrick" wrote:

> Any disadvantage of storing (a big) DataView in Session??
>
> I never heard of storing data in System.Web.HttpContext.Current? How does
> that work? Any disavantage over storing data in Session?
>
> "Elton W" wrote:
>
> > In fact, datagridâ??s data source will loss when it posts back. You need to
> > rebind the datagridâ??s data source. You donâ??t need to re-query data from DB.
> > You can save data source object in Session or Context. Then retrieve it when
> > needed.
> >
> > HTH
> >
> > Elton Wang
> >
> > "Patrick" wrote:
> >
> > > I had something like the following working:
> > > !!!!!!!!!! !!!!!!!!!! Start of Code snipet!!!!!!!!!! !!!!!!!!!!
> > > <asp:DataGrid id="FormListDataGrid" runat="server"
> > > AutoGenerateColumns="False" ShowHeader="true" HeaderStyle-CssClass="header"
> > > AllowSorting="true" OnSortCommand="SortCurrentMonth_OnClick"
> > > HeaderStyle-Height="25px">
> > > <Columns>
> > > <asp:HyperLinkColumn Runat="server" DataNavigateUrlField="FormName"
> > > DataNavigateUrlFormatString="ShowForm.aspx?form={0}" DataTextField="FormName"
> > > HeaderText="Form Name" SortExpression="FormName"></asp:HyperLinkColumn>
> > > <asp:BoundColumn DataField="Due Date" HeaderText="Due Date"
> > > DataFormatString="{0:d}" SortExpression="Due Date"/>
> > > <asp:BoundColumn DataField="Entity" HeaderText="Entity"
> > > SortExpression="Entity" />
> > > </Columns>
> > > </asp:DataGrid>
> > >
> > > protected void SortCurrentMonth_OnClick(Object source,
> > > DataGridSortCommandEventArgs e)
> > > {
> > > ((DataView) FormListDataGrid.DataSource).Sort= e.SortExpression;
> > > FormListDataGrid.DataBind();
> > > }
> > > !!!!!!!!!! !!!!!!!!!! End of Code snipet!!!!!!!!!! !!!!!!!!!!
> > >
> > > This aspx load up the DataGrid on page start up.
> > >
> > > However, I now created another ASPX for reporting, whose DataGrid is set to
> > > Visible=false initially, with the DataSource, etc. only set at the click of a
> > > button. Code-snippet as follows:
> > >
> > > ~~~~~~~~~~~~~~~Start of new Code snippet~~~~~~~~~~~~~~~
> > > <asp:DataGrid id="ReportDataGrid" runat="server"
> > > AutoGenerateColumns="False" ShowHeader="true"
> > > HeaderStyle-CssClass="header" AllowSorting="true"
> > > OnSortCommand="SortReport_OnClick" HeaderStyle-Height="25px" CellSpacing="5">
> > > <Columns>
> > > <asp:HyperLinkColumn Runat="server" DataNavigateUrlField="FormName"
> > > DataNavigateUrlFormatString="ShowForm.aspx?form={0}" DataTextField="FormName"
> > > HeaderText="Form Name" SortExpression="FormName"></asp:HyperLinkColumn>
> > > <asp:BoundColumn runat="server" DataField="Due Date" HeaderText="Due
> > > Date" DataFormatString="{0:d}"
> > > SortExpression="Due Date" />
> > >
> > > <asp:BoundColumn runat="server" DataField="Manager" HeaderText="Last
> > > Manager" SortExpression="Manager" />
> > > <asp:BoundColumn runat="server" DataField="DummyComments"
> > > HeaderText="Dummy Comments" />
> > > <asp:BoundColumn runat="server" DataField="Status" HeaderText="Status"
> > > SortExpression="Status"/>
> > > </Columns>
> > > </asp:DataGrid>
> > >
> > > private void ReportButton_Click(object sender, System.EventArgs e)
> > > {
> > > string reportSQL = "SELECT * FROM forms";
> > > //Render reportSQL now based upon selected criteria on the web form
> > > DataSet dataList = new DataSet();
> > >
> > > OdbcConnection Conn = new OdbcConnection("Driver={Microsoft Access Driver
> > > (*.mdb)};DBQ=c:\\dev\\outstandingForms.mdb");
> > >
> > > Conn.Open();
> > > OdbcDataAdapter accessDataAdapter = new OdbcDataAdapter(reportSQL,Conn);
> > > accessDataAdapter.Fill(dataList);
> > >
> > > DataView oView= new DataView(dataList.Tables[0]);
> > > ReportDataGrid.DataSource= oView;
> > > ReportDataGrid.DataBind();
> > > Conn.Close();
> > > ReportDataGrid.Visible= true;
> > >
> > > }
> > >
> > >
> > > protected void SortReport_OnClick(Object source,
> > > DataGridSortCommandEventArgs e)
> > > {
> > > ((DataView) ReportDataGrid.DataSource).Sort= e.SortExpression;
> > > ReportDataGrid.DataBind();
> > > }
> > > ~~~~~~~~~~~~~~~End of new Code snippet~~~~~~~~~~~~~~~
> > >
> > > The issue now is whenever I try to sort something by clicking on the column
> > > heading, I get an error, which is caused by an un-initialised
> > > ReportDataGrid.DataSource! How could I rectify this? I don't really want to
> > > re-run the query and re-set the DataSource, re-create the SQL everytime, do I?
> > >
> > >
> > > "Kevin Yu [MSFT]" wrote:
> > >
> > > > Hi Patrick,
> > > >
> > > > I agree with Elton that you have to assign e.SortExpression to the sort
> > > > expression of the DataView.
> > > >
> > > > oView.Sort = e.SortExpression;
> > > >
> > > > Here is an example:
> > > >
> > > > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
> > > > frlrfsystemwebuiwebcontrolsdatagridsortcommandeventargsclasssortexpressionto
> > > > pic.asp
> > > >
> > > > Kevin Yu
> > > > =======
> > > > "This posting is provided "AS IS" with no warranties, and confers no
> > > > rights."
> > > >
> > > >