473,396 Members | 1,666 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Data grid current page number?

Hi, I have a data grid that has the following properties

EnableViewState = false
AllowPaging = true
AllowSorting = true
AllowCustomPaging = false

now, when the page switches I want to get the current page number and
display it in a label on the form... but it doesnt seem to return anything
but zero no mater which page i am on in CurrentPageIndex property of the
grid how do you get the current page number? thanks
Nov 18 '05 #1
7 3346
"Brian Henry" <br**********@newsgroups.nospam> wrote in message
news:uh**************@TK2MSFTNGP11.phx.gbl...
Hi, I have a data grid that has the following properties

EnableViewState = false
AllowPaging = true
AllowSorting = true
AllowCustomPaging = false

now, when the page switches I want to get the current page number and
display it in a label on the form... but it doesnt seem to return anything
but zero no mater which page i am on in CurrentPageIndex property of the
grid how do you get the current page number? thanks


Try leaving ViewState turned on and see if that helps.
--
John Saunders
johnwsaundersiii at hotmail
Nov 18 '05 #2
Brian,

Assuming that CurrentPageIndex can't be zero for all pages (because if it
was you wouldn't be able to switch pages) the page number will always be
CurrentPageIndex + 1

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Brian Henry" <br**********@newsgroups.nospam> wrote in message
news:uh**************@TK2MSFTNGP11.phx.gbl...
Hi, I have a data grid that has the following properties

EnableViewState = false
AllowPaging = true
AllowSorting = true
AllowCustomPaging = false

now, when the page switches I want to get the current page number and
display it in a label on the form... but it doesnt seem to return anything
but zero no mater which page i am on in CurrentPageIndex property of the
grid how do you get the current page number? thanks

Nov 18 '05 #3
yes that helps, but also sends me back a 1MB HTML file *LOL* not good for
internet connections...
"John Saunders" <jo**************@notcoldmail.com> wrote in message
news:uC**************@TK2MSFTNGP12.phx.gbl...
"Brian Henry" <br**********@newsgroups.nospam> wrote in message
news:uh**************@TK2MSFTNGP11.phx.gbl...
Hi, I have a data grid that has the following properties

EnableViewState = false
AllowPaging = true
AllowSorting = true
AllowCustomPaging = false

now, when the page switches I want to get the current page number and
display it in a label on the form... but it doesnt seem to return anything but zero no mater which page i am on in CurrentPageIndex property of the
grid how do you get the current page number? thanks


Try leaving ViewState turned on and see if that helps.
--
John Saunders
johnwsaundersiii at hotmail

Nov 18 '05 #4
Hi Brian,

As John has mentioned, the DataGrid's CurrentPageIndex property will work
only when we enable its ViewState because the DataGrid maintain this
information in the ViewState collection. If we disable the View
State, this property will always return 0.

In addtion to keeping the Viewstate turn on, we can use some other means to
keep the currentPageIndex for the datagrid, for example, we can use a
invisible Label or a <input type="hidden" > html field to store the
DataGrid's index. Then when in the DataGrid's PageIndex change event, we
update this value so that we can retrieve back it later. This allow us
still let the DataGrid with ViewState disabled.
Here is a demo page I've made using the above means, you can have a look if
you feel anything unclear:

============aspx page============
<HTML>
<HEAD>
<title>PagingGrid</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="100%" align="center">
<tr>
<td><input id="dgOriginalPageIndex" type="hidden" value="0"
runat="server"></td>
</tr>
<tr>
<td><asp:datagrid id="dgPage" runat="server" EnableViewState="False"
PageSize="6" AllowPaging="True"
AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="index"
HeaderText="Index"></asp:BoundColumn>
<asp:BoundColumn DataField="name"
HeaderText="Name"></asp:BoundColumn>
<asp:BoundColumn DataField="price"
HeaderText="Price"></asp:BoundColumn>
</Columns>
<PagerStyle PageButtonCount="6" Mode="NumericPages"></PagerStyle>
</asp:datagrid>
</td>
</tr>
</table>
</form>
</body>
</HTML>

=========code behind class========
public class PagingGrid : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlInputHidden dgOriginalPageIndex;
protected System.Web.UI.WebControls.DataGrid dgPage;

private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
Session["DATASOURCE"] = GetDataSource();
}

Bind_Grid();
}

protected DataTable GetDataSource()
{
DataTable tb = new DataTable();
tb.Columns.Add("index");
tb.Columns.Add("name");
tb.Columns.Add("price",typeof(double));

DataRow dr = null;
bool[] flags = {true,false};
for(int i=1;i<=20;++i)
{
dr = tb.NewRow();
dr["index"] = i.ToString();
dr["name"] = "Name" + i.ToString();
dr["price"] = 3.434 * (i%3 +1);

tb.Rows.Add(dr);
}

return tb;
}

protected void Bind_Grid()
{
DataTable tb =(DataTable)Session["DATASOURCE"];
dgPage.DataSource = tb;
dgPage.DataBind();

}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dgPage.PageIndexChanged += new
System.Web.UI.WebControls.DataGridPageChangedEvent Handler(this.dgPage_PageIn
dexChanged);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void dgPage_PageIndexChanged(object source,
System.Web.UI.WebControls.DataGridPageChangedEvent Args e)
{
Response.Write("<br>Original Page Index: "+dgOriginalPageIndex.Value );
Response.Write("<br>New Page Index: " + e.NewPageIndex);

dgPage.CurrentPageIndex = e.NewPageIndex;
dgOriginalPageIndex.Value = e.NewPageIndex.ToString();
Bind_Grid();
}
}

===========================================
Hope helps. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #5
when you use Session() does it send that information to the client with the
HTML page like viewstate() does or is session completely server side? that
is one of the concerns i had was using session() to store the data source if
it was sent to the client too in the ViewState data also.. thanks!
"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:5z****************@cpmsftngxa06.phx.gbl...
Hi Brian,

As John has mentioned, the DataGrid's CurrentPageIndex property will work
only when we enable its ViewState because the DataGrid maintain this
information in the ViewState collection. If we disable the View
State, this property will always return 0.

In addtion to keeping the Viewstate turn on, we can use some other means
to
keep the currentPageIndex for the datagrid, for example, we can use a
invisible Label or a <input type="hidden" > html field to store the
DataGrid's index. Then when in the DataGrid's PageIndex change event, we
update this value so that we can retrieve back it later. This allow us
still let the DataGrid with ViewState disabled.
Here is a demo page I've made using the above means, you can have a look
if
you feel anything unclear:

============aspx page============
<HTML>
<HEAD>
<title>PagingGrid</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="100%" align="center">
<tr>
<td><input id="dgOriginalPageIndex" type="hidden" value="0"
runat="server"></td>
</tr>
<tr>
<td><asp:datagrid id="dgPage" runat="server" EnableViewState="False"
PageSize="6" AllowPaging="True"
AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="index"
HeaderText="Index"></asp:BoundColumn>
<asp:BoundColumn DataField="name"
HeaderText="Name"></asp:BoundColumn>
<asp:BoundColumn DataField="price"
HeaderText="Price"></asp:BoundColumn>
</Columns>
<PagerStyle PageButtonCount="6" Mode="NumericPages"></PagerStyle>
</asp:datagrid>
</td>
</tr>
</table>
</form>
</body>
</HTML>

=========code behind class========
public class PagingGrid : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlInputHidden dgOriginalPageIndex;
protected System.Web.UI.WebControls.DataGrid dgPage;

private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
Session["DATASOURCE"] = GetDataSource();
}

Bind_Grid();
}

protected DataTable GetDataSource()
{
DataTable tb = new DataTable();
tb.Columns.Add("index");
tb.Columns.Add("name");
tb.Columns.Add("price",typeof(double));

DataRow dr = null;
bool[] flags = {true,false};
for(int i=1;i<=20;++i)
{
dr = tb.NewRow();
dr["index"] = i.ToString();
dr["name"] = "Name" + i.ToString();
dr["price"] = 3.434 * (i%3 +1);

tb.Rows.Add(dr);
}

return tb;
}

protected void Bind_Grid()
{
DataTable tb =(DataTable)Session["DATASOURCE"];
dgPage.DataSource = tb;
dgPage.DataBind();

}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dgPage.PageIndexChanged += new
System.Web.UI.WebControls.DataGridPageChangedEvent Handler(this.dgPage_PageIn
dexChanged);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void dgPage_PageIndexChanged(object source,
System.Web.UI.WebControls.DataGridPageChangedEvent Args e)
{
Response.Write("<br>Original Page Index: "+dgOriginalPageIndex.Value );
Response.Write("<br>New Page Index: " + e.NewPageIndex);

dgPage.CurrentPageIndex = e.NewPageIndex;
dgOriginalPageIndex.Value = e.NewPageIndex.ToString();
Bind_Grid();
}
}

===========================================
Hope helps. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #6
Hi Brian,

As for the Sesssion(SessionState), this is a user context based and which
is completely stored on the serverside. And the client keep its reference
to its serverside session by a SessionId. Generally, the sessionid is
stored in cookie. When the use request a page , the request will post with
this cookie so that the serverside can associate the proper session state
for the user.
And normally most sessionstate implement are in memory session, that means
t he session data all stored in the server's memory, so if we use session
too much , there may cause memory challenge to the server.

In conclusion, the ViewState store in the page content and will cause the
transfer issue when storing large data while the Session will cause server
memory concern, so we have to make our decision between them regarding on
our specified scenario.
Thanks.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #7
ah, thanks for clearing that up
"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:8g**************@cpmsftngxa06.phx.gbl...
Hi Brian,

As for the Sesssion(SessionState), this is a user context based and which
is completely stored on the serverside. And the client keep its reference
to its serverside session by a SessionId. Generally, the sessionid is
stored in cookie. When the use request a page , the request will post with
this cookie so that the serverside can associate the proper session state
for the user.
And normally most sessionstate implement are in memory session, that means
t he session data all stored in the server's memory, so if we use session
too much , there may cause memory challenge to the server.

In conclusion, the ViewState store in the page content and will cause the
transfer issue when storing large data while the Session will cause server
memory concern, so we have to make our decision between them regarding on
our specified scenario.
Thanks.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jawahar Rajan | last post by:
All, I have a datagrid that I use in a ASP.net web page that loads customer data based on the selected customer ID Some Customers will have no data in the database (which is oracle 9.2) . So I...
5
by: pmud | last post by:
Hi, I need to display columns in a data grid based on 7 different queries. Now I have 32 questions: 1. Is it possble to have 1 single data adapter with 7 queries & 1 data set or do I need to...
2
by: Les | last post by:
Hi can anyone help me, I have just graduated and have started working for a building developer which deals with a large quantity of drawings. As you can imagine these all need documenting...
1
by: krian | last post by:
Hi, I need a help from anybody. My problem is here I wrote two WebApplication in ASP.net Using C#. The name of the applications are (Journal.aspx and Payment.aspx). These Two pages have DataGrids...
3
by: Simon Harris | last post by:
Hi All, I have a data grid which displays country names. I now wish to display the country flag images above the names. Can someone please advise how I display an image in a datagrid? I have a...
2
by: Brian Henry | last post by:
Hi, I have a data grid that is set up like this Page items displayed = 10 EnableViewState = false (i dont want to send large amounts of data over the internet!) CustomPaging = false...
4
by: Vasantha peddireddy | last post by:
I am posting a page to another page (form post). The data grid on the second page is being populated with data. Now, on page load of the second page, I would like to send the grid data on this page...
3
by: kingflux | last post by:
Hello, and thank you in advance for any help you can provide. Each line in our datagrid control contains a product number, description, and a textbox for the user to enter a quantity-to-order. ...
6
by: slinky | last post by:
I found the following code to transfer datagrid data to an Excel file. Is this written in C#?... I'm a vb.netter. I'm just not sure where to place the code to experiment on it. Should I place it in...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.