GridView and SqlDataSource to update data
GridViewEditExample.aspx
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>asp.net GridView and SqlDataSource example: updating data</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Gray">Example: Updating Data</h2>
<asp:SqlDataSource
ID="SqlDataSource1"
runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT CategoryID, CategoryName, Description FROM Categories"
UpdateCommand="UPDATE Categories SET CategoryName=@CategoryName, Description=@Description WHERE CategoryID=@original_CategoryID"
OldValuesParameterFormatString="original_{0}"
>
</asp:SqlDataSource>
<asp:GridView
ID="GridView1"
runat="server"
DataSourceID="SqlDataSource1"
DataKeyNames="CategoryID"
AutoGenerateColumns="false"
AutoGenerateEditButton="true"
BackColor="HotPink"
ForeColor="AntiqueWhite"
BorderColor="Orange"
BorderStyle="Double"
BorderWidth="2"
AllowSorting="false"
AllowPaging="true"
PageSize="5"
HeaderStyle-BackColor="DarkOrange"
>
<Columns>
<asp:BoundField HeaderText="Category ID" DataField="CategoryID" />
<asp:BoundField HeaderText="Category Name" DataField="CategoryName" />
<asp:BoundField HeaderText="Description" DataField="Description" />
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
- asp.net FormView example: how to use ItemTemplate, Eval()
- asp.net SqlDataReader example: how to use Read() method to populate ListBox
- GridView example: how to use GridView in asp.net
- GridView example: how to populate GridView from SqlDataSource in asp.net
- DetailsView and SqlDataSource example: Using Insert, Edit
- DataReader example: how to use DataReader in asp.net
- DataAdapter example: how to use DataAdapter in asp.net
- SqlParameter example: how to use SqlParameter in asp.net