I'm trying to change a column value on a gridview (.net 3.5) using the RowUpdating event. The event is fired and I set a new value - but the table is not updated.
<asp:GridView ID="GridViewHotels" runat="server" AllowSorting="True"
AutoGenerateColumns="False" DataSourceID="SqlDataSourceHotels"
OnRowUpdating="GridViewHotels_RowUpdating">
...
<asp:BoundField DataField="lat" HeaderText="lat" SortExpre开发者_如何学Gossion="lat" />
...
<asp:SqlDataSource ID="SqlDataSourceHotels" runat="server"
UpdateCommand="UPDATE [hotels] SET ... [lat] = @lat .... WHERE [id] = @id">
This is the event code (which is called):
protected void GridViewHotels_RowUpdating(Object sender,
GridViewUpdateEventArgs e)
{
e.NewValues["lat"] = "xxx";
}
And yet ,the "lat" field is not updated
What is your grid datasource bound to? If it is a dataset you're keeping in ViewState, etc, you will have to call AcceptChanges and rebind the data. If the underlying data is in a database, simply rebind the grid from the data source (after updating it), i.e. refresh it from sql server/whatever your data source is.
I believe you need a connection string in your SQLDataSource.
精彩评论