1) If we first set DropDownList.SelectedIndex to some value and then rebind control to data source, it’s SelectedIndex property will be reset to default. So why doesn’t something similar happen with GridView.SelectedIndex and GridView.EditIndex? It seems that unlike DropDownList, GridView doesn’t reset these two properties ( to their default values ) after a re-bind.
2)
If you set the GridView.EditIndex property after a postback or in handlers for events that are raised later than the Load event, the GridView control might not enter edit mode for the specified row. If you read the value of this property in other event handlers, the index is not guaranteed to reflect the row that is being edited.
Why could setting GridView.EditIndex after postback or in handlers raised after Load event cause GridView not to enter into Edit mode?
thank you
In order for a GridView row to be in edit mode, the grid must be databound. So resetting EditIndex wouldn’t make much sense. As for SelectedIndex… I imagine that is just simply a design decision.
As for number two… I think this text is misleading. Does it come from MSDN? I think what it is trying to say is “don’t do this or allow it to happen:”
You see? What row are we editing now?
[Edit]
This has everything to do with Question 2. You see, with the above code we are actually still editing row X. (but most likely, you will get a state error when you go to postback). Setting EditIndex itself does not put the GridView into edit mode… so your question is somewhat moot to begin with. What actually puts a row in edit mode is having this property set when the grid is databound. EditIndex really just tells the Render method which template to use: ItemTemplate or EditTemplate.
Like I said before, I believe the text you quoted is misleading. The important thing is knowing when the data binding happens. The text you quoted seems to assume that that is happening during Load.