Click here to Skip to main content
12,406,342 members (65,648 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP ASP.NET ASP.NET4
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

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


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 30-Jan-13 0:48am
GDdixit542
Updated 30-Jan-13 1:10am
v3
Comments
AshishChaudha 30-Jan-13 7:08am
   
Please share code of rowcommand too.
khiladi786 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...?

Turbo_23 30-Jan-13 7:09am
   
hi...post your code here.
Vinodh.B 30-Jan-13 7:29am
   
Post code written in row command .
khiladi786 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...?


Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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];
 

 
}
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Just call the fillgrid function as follows .
Solution 1
FillGrid();
   grdView.PageIndex = e.NewPageIndex;
   grdView.DataBind();


Solution 2
Add the following code in Page index Changing

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() + ".";
    }
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160730.1 | Last Updated 30 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100