Edit/Update a single GridView field

2019-08-02 12:09发布

问题:

I've got a GridView on an ASP.NET page, on which I need to edit a single field in a row when a user clicks the 'Edit' button on that row, and have a SQL database table updated with whatever the user enters.

I'm added a CommandField to my GridView, so I now have an 'Edit' button at as the last column in each row. I'm getting the data from the database using LINQ.

My question is - how do I wire it so that when I click this 'Edit' button, the user is allowed to edit a single item in this row, then update the database with the text the user enters?

Any help is appreciated.

Thanks!

回答1:

Here are some Grid options for use with ASP.NET MVC:

grid controls for ASP.NET MVC?



回答2:

Set the fields you don't want to edit to read only:

            <asp:BoundField DataField="CustomerName" HeaderText="CustomerName" 
            ReadOnly="True" SortExpression="CustomerName" />