Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GridView wont allow me to edit 1

Status
Not open for further replies.

litton1

Technical User
Joined
Apr 21, 2005
Messages
584
Location
GB
Hi all, I have a GridView. It has just been dropped on the form and filled from a Dataset in the code behind. The GridView first tag now looks like so..
Code:
<asp:GridView ID="GridViewTestResults" runat="server" AutoGenerateEditButton=true AutoGenerateColumns="False" DataKeyNames="TestId" OnRowDataBound="GridViewTestResults_RowDataBound" OnRowEditing="GridViewTestResults_RowEditing" >

But it will not allow me to edit the Grid data, is there something I am missing?
Thx T


Age is a consequence of experience
 
I sorta guessed i would need to do something in there and have been trying to get the right code but without much success. I would have thought I would need to change the RowState.
Code:
GridViewTestResults.Rows[ e.NewEditIndex ].RowState = DataControlRowState.Edit;

but that didnt seem to work?
Any pointers appreciated.
Thanks T



Age is a consequence of experience
 
got it!
Code:
myGridView.EditIndex = e.NewEditIndex;

Thanks for your reply jbenson001

Age is a consequence of experience
 
More problems with editing the gridview :(...
When i click edit on a row the grid vanishes. If i resubmit my query (a button above the grid) then the grid comes back but in edit mode. Can anyone make sense of this?
Thx T

Age is a consequence of experience
 
A thought.. it may be something to do with...
Code:
protected void GridViewTestResults_RowEditing( object sender, GridViewEditEventArgs e )
{    
  GridViewTestResults.EditIndex = e.NewEditIndex;
  DataBind( );
}



Age is a consequence of experience
 
I have now found that if I remove the DataBind( ); from the editing event then click edit once, I stay in ReadOnly mode but if i click edit twice it goes into edit mode??

Does this help identifying the fault?

Age is a consequence of experience
 
An update...
I have now discovered that the GridViewTestResults_RowEditing is being called on the first click but the grid does not go to edit mode till the second so i guess the grid must have already been built to send back to the page? Not sure what to do about it though.

Age is a consequence of experience
 
It may be worth you following an example based on Northwind, just to see how the GridView can be used for editing (then you can apply the functionality to your page). Have a look at the walkthrough here for an example you can create yourself.


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244.
 
thx ca8msm I will do that this afternoon

Age is a consequence of experience
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top