IT Community - Software Programming, Web Development and Technical Support

Paging in Grid

This is a discussion on Paging in Grid within the ASP and ASP.NET Programming forums, part of the Web Development category; Hi, We can set the paging option to true as " AllowPaging="true" " in the page directive. ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > ASP and ASP.NET Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 03-26-2008, 04:22 AM
Kirubhananth Kirubhananth is offline
D-Web Programmer
 
Join Date: Feb 2008
Location: My native is Madurai but now in Chennai
Posts: 61
Kirubhananth is on a distinguished road
Send a message via AIM to Kirubhananth Send a message via Skype™ to Kirubhananth
Question Paging in Grid

Hi,

We can set the paging option to true as " AllowPaging="true" " in the page directive.

My problem is if i did the dB connection statically then the paging option is working automatincally without writing any code except the " AllowPaging="true" " .

While connecting the grid with the DB through code, then how can we change the page through the C# code?

The code for this in VB.NET is

mygridview.PageIndex = e.NewPageIndex
mygridview.DataSource = ds.Tables(0)
mygridview.DataBind()


Please send me code in C#.
__________________
--Kirubhaa. Born to win--
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-26-2008, 04:33 AM
poornima poornima is offline
D-Web Sr.Programmer
 
Join Date: Dec 2007
Posts: 189
poornima is on a distinguished road
Smile Re: Paging in Grid

Hi,
If u want to change the Page then u have to change the Page Index of the GridView.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-26-2008, 05:05 AM
Kirubhananth Kirubhananth is offline
D-Web Programmer
 
Join Date: Feb 2008
Location: My native is Madurai but now in Chennai
Posts: 61
Kirubhananth is on a distinguished road
Send a message via AIM to Kirubhananth Send a message via Skype™ to Kirubhananth
Smile Re: Paging in Grid

Hi,

Can you send me the code for doing this? I have it in VB.NET.
But i want it in C#.
__________________
--Kirubhaa. Born to win--
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-26-2008, 09:54 PM
poornima poornima is offline
D-Web Sr.Programmer
 
Join Date: Dec 2007
Posts: 189
poornima is on a distinguished road
Smile Re: Paging in Grid

Hi kirubananth,

Use the following coding for setting the page Size..PageSize is used to display no.of.records per page.Here I used PageSize="5".So It will display '5-records' per page.

<asp:GridView ID="GridViewDemo" runat="server" PageSize ="5"
OnPageIndexChanging="GridViewDemo_PageIndexChangin g" AutoGenerateColumns="false" AllowPaging="true" DataKeyNames="Sno" >
<Columns>
<asp:TemplateField HeaderText="Sno">
<ItemTemplate><%#DataBinder.Eval(Container.DataIte m,"sno")%></ItemTemplate>
</asp:TemplateField>
</Columns>
<Columns>
<asp:TemplateField HeaderText="Sname">
<ItemTemplate><%#DataBinder.Eval(Container.DataIte m,"sname")%></ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>


In code-Behind,u have to set the page Index for GridView using GridViewDemo_PageIndexChanging.

protected void GridViewDemo_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridViewDemo.PageIndex = e.NewPageIndex;
loadData();
}

public void loadData()//To load data in GridView
{
SqlCommand cmd = new SqlCommand("select * from stud", con);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds, "stud");
GridViewDemo.DataSource = ds;
GridViewDemo.DataBind();
}
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 03-26-2008, 11:49 PM
Kirubhananth Kirubhananth is offline
D-Web Programmer
 
Join Date: Feb 2008
Location: My native is Madurai but now in Chennai
Posts: 61
Kirubhananth is on a distinguished road
Send a message via AIM to Kirubhananth Send a message via Skype™ to Kirubhananth
Question Re: Paging in Grid

Hi poornima,

The problem is ,
if i place the dot near the object e then i get only 4 functions as

e.Equals();
e.GetHashCode();
e.GetType();
e.GetType();

That is the problem for me.
__________________
--Kirubhaa. Born to win--
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 03-26-2008, 11:59 PM
Kirubhananth Kirubhananth is offline
D-Web Programmer
 
Join Date: Feb 2008
Location: My native is Madurai but now in Chennai
Posts: 61
Kirubhananth is on a distinguished road
Send a message via AIM to Kirubhananth Send a message via Skype™ to Kirubhananth
Smile Re: Paging in Grid

Sorry,
I found my error. I placed the dode in the selected_indexchanged and not selected_indexchanging.

Thank you for your timely help poornima.
__________________
--Kirubhaa. Born to win--
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-03-2008, 08:47 PM
GDevakii GDevakii is offline
D-Web Sr.Programmer
 
Join Date: Aug 2007
Posts: 138
GDevakii is on a distinguished road
Smile Re: Paging in Grid

<HTML>
<HEAD>
<title>DatagridPaging</title>
</HEAD>
<body>
<form id="Form1" runat="server">

<aspataGrid ID="dgrdAccounts" runat="server"
AllowPaging="True" PageSize="5"
OnPageIndexChanged="drdaccounts_pageIndexChanged"
cellpadding="3">
</aspataGrid>
</form>
</body>
</HTML>

Write the following code in the Code behind window

Imports System.Data.SqlClient

Dim myConnection As SqlConnection = New SqlConnection("Data Source=SYS1;Integrated Security=SSPI;Initial Catalog=FinAccounting")
Const strSQL As String = "SELECT AccountCode,Accountname,AccountDescription FROM AccountsTable"
Dim myDataAdapter As SqlDataAdapter = New SqlDataAdapter(strSQL, myConnection)
Dim dstaccounts As New DataSet()

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack() Then
BindDataGrid()
End If
End Sub

Sub BindDataGrid()
myConnection.Open()
myDataAdapter.Fill(dstaccounts, "AccountsTable")
dgrdAccounts.DataSource = dstaccounts
dgrdAccounts.DataBind()
End Sub

Sub drdaccounts_pageIndexChanged(ByVal s As Object, ByVal e As DataGridPageChangedEventArgs)
dgrdAccounts.CurrentPageIndex = e.NewPageIndex
BindDataGrid()
End Sub
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 11-14-2008, 05:07 AM
levelup2 levelup2 is offline
D-Web Trainee
 
Join Date: Nov 2008
Posts: 8
levelup2 is on a distinguished road
Default Re: Paging in Grid

is really useful for me
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 11-28-2008, 01:51 AM
niaz13 niaz13 is offline
D-Web Trainee
 
Join Date: Nov 2008
Posts: 12
niaz13 is on a distinguished road
Default Re: Paging in Grid

onnection statically then the paging option is working automatincally without writing any code excep

and this is so useful to me
__________________
web hosting ringtone downloads
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Paging Concept in Repeater? poornima ASP and ASP.NET Programming 1 03-21-2008 09:48 PM
How to implement Custom Paging in DataList? poornima ASP and ASP.NET Programming 0 01-24-2008 12:57 AM
Wt mean by paging? prasath Operating Systems 1 07-19-2007 05:08 AM
ASP with paging elements kingmaker HTML, CSS and Javascript Coding Techniques 1 07-19-2007 12:32 AM
Paging array in PHP kingmaker PHP Programming 0 07-16-2007 11:11 PM


All times are GMT -7. The time now is 07:00 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0