Click here to Skip to main content
15,915,019 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
in most of the gridview's it is always written

C#
GridView1.EditIndex= -1;


can anyone tell me in detail whats the use of it..?
Posted

If you want to cancel the Edit mode in Grid view.. set GridName.EditIndex=-1;

We usually use this when you use built in Edit Functionality inside the GridView.

Eg: If you want to display 3rd record inside the grid in Edit mode

GridName.EditIndex=2;

After Editing, on click of Save

GridName.EditIndex=-1; //-So that it goes back to normal view
 
Share this answer
 
Whenever you edit gridview a editindex is working.

by setting
GridView1.EditIndex= -1;

Gridview changed into normal mode from EDit mode.
 
Share this answer
 
Asp.net grid view is having list or array of gridviewrows, and as all the list and array are starting index is 0, so if you set edit index of grid view to 0 or 1 or any other than it will make that indexed row in edit mode. so if you need your grid view in only read only mode then you need to set -1 as edit index. -1 means no row are in edit mode.
 
Share this answer
 
Comments
prashantttt 23-Oct-13 8:47am    
do you mean whatever data is present in gridview it's a list and the way we manage index of list in that same way we have to manage index of gridview...?

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