views:

39

answers:

1

Hi Guys,

I have an ASP.NET GridView which displays a list of neighborhoods.

I wish a user (administrator) to be able to edit the neighborhood name.

Now, the database is quite complex, and as such, i can't simply provide an UpdateCommand / SqlDataSource for the GridView.

I bind the data manually (on first load, and on the PageIndexChanging event).

Binding/listing paged data is working fine.

However, i'm having trouble trying to UPDATE the data.

The user clicks the "Edit" button, the textbox for the neighborhood name is shown, i change the text, click "Update", but the RowUpdating event is not firing.

I basically want to grab the row that was edited, and perform a custom update using LINQ.

Is this not possible with a GridView? If it's not, what are my alternatives? A repeater with LinkButtons and a hidden textbox that can swap in/out the labels?

This is my GridView markup:

<asp:GridView ID="NeighborhoodsGrid" 
              AllowPaging="true"
              PageSize="10"
              AutoGenerateColumns="false"
              EnableViewState="false"
              OnPageIndexChanging="NeighborhoodsGridPageIndexChanging"
              OnRowDataBound="NeighborhoodsGridRowDataBound"
              OnRowEditing="NeighborhoodsGridRowEditing" 
              OnRowCancelingEdit="NeighborhoodsGridRowCancellingEdit" 
              OnRowUpdating="NeighborhoodsGridRowUpdating" 
              AutoGenerateEditButton="true"
              runat="server">

And the code-behind:

protected void NeighborhoodsGridRowUpdating(object sender, GridViewUpdateEventArgs e)
{
   GridViewRow updatedRow = NeighborhoodsGrid.Rows[e.RowIndex]; // not firing. =(
}

I also have the GridView wrapped in an UpdatePanel, if that makes any difference (don't think it should).

Any ideas or alternative recommendations?

+2  A: 

Nevermind guys, my bad.

I had EnableViewState="false".

I have no idea why this would affect the firing of an event, nor how the other events were even working.

Anyway, i set that to true and the event is fired.

I always try and set ViewState to false then turn it on as i need it.

Payed the price this time. =)

Anyway problem solved.

RPM1984
BOOM!! Viewstate Explosion. Good thing there's MVC!!!
rockinthesixstring
=) Hell yes, this is an admin page for an ASP.NET Web Forms application, so i "succumbed" to the drag-and-drop hell. =) We're rewriting the website tho - MVC FTW.
RPM1984