Click here to Skip to main content
15,880,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a problem ...i write the following code for paging in gridview.....

"
select gridview and goto properties window and click on events button

double click on pageindexchanging event

and set

C#
Allowpaging=true
// for gridview
in pageindex changing event i write the following code...


C#
gridview1.pageindex=e.newpageindex;
//gridbindingcode
gridview1.databind();

"


and in my grid view i also use the row command ...

when i run my page ...its load properly but on changing pageindex it give an error on row command ....

that your row index cannot be less than zero..whats the problem frnds?
Posted
Updated 30-Jan-13 1:10am
v3
Comments
AshishChaudha 30-Jan-13 7:08am    
Please share code of rowcommand too.
GDdixit 2-Feb-13 3:54am    
int index;

index = Convert.ToInt32(e.CommandArgument);

GridViewRow row = gridview1.Rows[index];
label lbl=GridView1.rows[index].cells[0];
string VOrderId=lbl.Text;

and then ....
here i perform my delete operation with a simple procedure..

actually i understand the problem but can not finding solution...
i think problem is that value of row index is start from zero....

but when i using paging ....row index value seen to be start from negative(i think so)...so any help frnds...?

[no name] 30-Jan-13 7:09am    
hi...post your code here.
Vinodh.B 30-Jan-13 7:29am    
Post code written in row command .
GDdixit 2-Feb-13 3:54am    
int index;

index = Convert.ToInt32(e.CommandArgument);

GridViewRow row = gridview1.Rows[index];
label lbl=GridView1.rows[index].cells[0];
string VOrderId=lbl.Text;

and then ....
here i perform my delete operation with a simple procedure..

actually i understand the problem but can not finding solution...
i think problem is that value of row index is start from zero....

but when i using paging ....row index value seen to be start from negative(i think so)...so any help frnd...?



Try below code in your rowcommand event of gridview

protected void gridview1_RowCommand(object sender, GridViewCommandEventArgs e)

{

        int index = 0;

        index = Convert.ToInt32(e.CommandArgument.ToString());

        GridViewRow row = gridview1.Rows[index];



}
 
Share this answer
 
Just call the fillgrid function as follows .
Solution 1
C#
FillGrid();
   grdView.PageIndex = e.NewPageIndex;
   grdView.DataBind();


Solution 2
Add the following code in Page index Changing

C#
if (CustomersGridView.EditIndex != -1)
    {
      // Use the Cancel property to cancel the paging operation.
      e.Cancel = true;

      // Display an error message.
      int newPageNumber = e.NewPageIndex + 1;
      Message.Text = "Please update the record before moving to page " +
        newPageNumber.ToString() + ".";
    }
 
Share this answer
 

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