Hi,
One way is to use
SqlDataSource
as data source of the
GridView
and set
AutoGenerateEditButton
to true. And set UpdateCommand attribute of SqlDataSource to your update statement.
GridView
will display a column with
Edit
button that you can use to update its data to the database.
<asp:GridView
ID="GridView1"
runat="server"
AutoGenerateColumns="False"
DataKeyNames="DepartmentID"
DataSourceID="SqlDataSource1"
AutoGenerateEditButton="true">
<Columns>
<asp:BoundField DataField="DepartmentID" HeaderText="DepartmentID"
InsertVisible="False" ReadOnly="True" SortExpression="DepartmentID" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
</Columns>
</asp:GridView>
<asp:sqldatasource xmlns:asp="#unknown">
ID="SqlDataSource1"
runat="server"
ConnectionString="<%$ ConnectionStrings:pagingConnectionString %>"
SelectCommand="SELECT [DepartmentID], [Name] FROM [Departments]"
UpdateCommand="UPDATE Departments SET Name=@Name WHERE DepartmentID=@DepartmentID">
</asp:sqldatasource>