Click here to Skip to main content
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 0:48am
GDdixit523
Edited 30-Jan-13 1: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 OriginalGriff 310
1 PhilLenoir 164
2 Richard MacCutchan 160
3 Sharmanuj 146
4 Magic Wonder 129
0 Sergey Alexandrovich Kryukov 6,081
1 OriginalGriff 5,115
2 CPallini 2,473
3 Richard MacCutchan 1,597
4 Abhinav S 1,505


Advertise | Privacy | Mobile
Web01 | 2.8.140814.1 | Last Updated 30 Jan 2013
Copyright © CodeProject, 1999-2014
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