Click here to Skip to main content
11,480,148 members (64,326 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP ASP.NET ASP:NET ASP>NET , +
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 1:48am
GDdixit531
Edited 30-Jan-13 2:10am
v3
Comments
AshishChaudha at 30-Jan-13 7:08am
   
Please share code of rowcommand too.
khiladi786 at 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 at 30-Jan-13 7:09am
   
hi...post your code here.
Vinodh.B at 30-Jan-13 7:29am
   
Post code written in row command .
khiladi786 at 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
0 Sergey Alexandrovich Kryukov 7,890
1 OriginalGriff 7,556
2 Sascha Lefèvre 3,064
3 Maciej Los 2,491
4 Richard Deeming 2,335


Advertise | Privacy | Mobile
Web03 | 2.8.150520.1 | Last Updated 30 Jan 2013
Copyright © CodeProject, 1999-2015
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