Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello there,

Can anyone help me here.

I have a datagrid diplaying the records from database. I want to display first 10 records and then expect user to click next button on the form and then display next 10 records in datagrid and so on.

while keeping check in datagrid i am not able to capture if the next button has been clicked or not.

Thanks
hitched hike
Posted
Comments
[no name] 25-Jun-12 7:35am    
"Can anyone help me here"... I am sure that someone could if you posted the code that demonstrates your problem.

in datagridview we dont have property like allowpaging.
A Simple Way for Paging in DataGridView in WinForm Applications[^]
once look at this it may helps u.
 
Share this answer
 
Comments
Member 8655072 25-Jun-12 10:56am    
I have tried to do the paging by implementing next and prev button and on every click i tried to fill the data grid with corresponding 10 results. It displays first 10 results and then for next 10 it says

Index was out of range. Must be non-negative and less that the size of the collection

Parameter name: index

can you pls guide me...how to check this limit
Member 8655072 25-Jun-12 11:12am    
Thax Sandeep, it gave me direction to implement my solution. It is working now
sandeep nagabhairava 25-Jun-12 11:15am    
you welcome...:)
Best of luck...
Try This :

C#
1 . PageIndexChanging is a Method of Gridview.
2.  Make Gridview AllowPaging True in Property of Gridview.

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
       
        GridView1.PageIndex = e.NewPageIndex;
        string str="select * from ABC";
        sqldataadapter ad=new Sqldatadapter(str,connection);
        dataset ds=new dataset();
         ad.fill(ds);

         Gridview1.Datasource=ds;
         Gridview1.databind();

    }



this will Help You.
 
Share this answer
 
v2
Comments
Sandeep Mewara 25-Jun-12 11:59am    
Comment from OP:
thx Mits for the reply but unfortunately my data grid variable is not showing me allowpaging property...don't know why..
I am new to c#
i m using windows forms and datagrid is on one of the forms
Calling this function everytime to display data via next and previous button_click() function
C#
 private void CreateTable
{                     
            try
            {
                int count = 0;
                startingRec = curPage * 10;
                int noOfRec_to_display = startingRec + 10; ;  

                for (int i = startingRec; i < noOfRec_to_display; i++)
                {
                    try
                            {
                                Image img = Image.FromFile("<complete path="">www.jpg"                                Bitmap result = new Bitmap(100, 100);
                                using (Graphics g = Graphics.FromImage((Image)result))
                                                                        g.DrawImage(new Bitmap("www.jpg"), 0, 0, 100, 100);
                                    
                                this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
                                dataGridView1.Rows.Add(m_PrimaryLotId[i], m_LotId[i], m_Title[i], result);
                                dataGridView1.Rows[count++].Height = 100;
                                dataGridView1.AllowUserToAddRows = false;

                            }
                            catch (System.IO.FileNotFoundException ex)
                            {
                                MessageBox.Show(ex.Message);
                            }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
 
Share this answer
 
v2
Comments
Sandeep Mewara 25-Jun-12 12:01pm    
Is this an answer to your question or an extension?
Member 8655072 26-Jun-12 5:57am    
sandeep this is the solution finally i implemented to view 10 records per page in datagrid.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900