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. ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
|
#1
| |||
| |||
| 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-- |
|
#2
| |||
| |||
| Hi, If u want to change the Page then u have to change the Page Index of the GridView. |
|
#3
| |||
| |||
| 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-- |
|
#4
| |||
| |||
| 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(); } |
|
#5
| |||
| |||
| 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-- |
|
#6
| |||
| |||
| 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-- |
|
#7
| |||
| |||
| <HTML> <HEAD> <title>DatagridPaging</title> </HEAD> <body> <form id="Form1" runat="server"> <asp ataGrid ID="dgrdAccounts" runat="server" AllowPaging="True" PageSize="5" OnPageIndexChanged="drdaccounts_pageIndexChanged" cellpadding="3"> </asp ataGrid></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 |
|
#8
| |||
| |||
| is really useful for me |
|
#9
| |||
| |||
| onnection statically then the paging option is working automatincally without writing any code excep and this is so useful to me |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Paging Concept in Repeater? | poornima | ASP and ASP.NET Programming | 1 | 03-21-2008 08:48 PM |
| How to implement Custom Paging in DataList? | poornima | ASP and ASP.NET Programming | 0 | 01-23-2008 11:57 PM |
| Wt mean by paging? | prasath | Operating Systems | 1 | 07-19-2007 04:08 AM |
| ASP with paging elements | kingmaker | HTML, CSS and Javascript Coding Techniques | 1 | 07-18-2007 11:32 PM |
| Paging array in PHP | kingmaker | PHP Programming | 0 | 07-16-2007 10:11 PM |
Our Partners |