i suggest you to work out in this way. i have made an example.
will display you the edit command button do it from back end.
This is my grid:
<asp:GridView runat="server" AutoGenerateColumns="false" ID="grdCustomers" DataKeyNames="CustomerID" AllowSorting="true"
OnRowEditing="grdCustomers_RowEditing" OnRowDeleting="grdCustomers_RowDeleting" HeaderStyle-BackColor = "green"
OnRowUpdating="grdCustomers_RowUpdating" OnRowCancelingEdit="grdCustomers_RowCancelingEdit" AllowPaging="false" ShowFooter="true" >
<Columns>
<asp:TemplateField HeaderText="Customer Id">
<ItemTemplate>
<asp:Label Text='<%#Eval("CustomerID")%>' HeaderText="" runat="server" ID="lblcustomerId" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Contact Name">
<ItemTemplate>
<asp:Label Text='<%#Eval("ContactName")%>' ID="lblCustomerName" runat="server" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtContactName" runat="server" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="City">
<ItemTemplate>
<asp:Label id="lblCity" Text='<%#Eval("City")%>' runat="server" />
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlCity1" runat="server" DataTextField="City" DataValueField="City"></asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="true" HeaderText="Edit" />
</Columns>
</asp:GridView>
My Back End Code to bind data:
Protected Sub GetAllCustomersData()
' List to Hold the results
'Type of binding
Dim myBinding As New BasicHttpBinding
'Endpoint name defining
Dim myEndPoint As New EndpointAddress(ConfigurationManager.AppSettings("CustomerServiceUrl").ToString())
'Registering Service Reference
Dim MychannelFactory As ChannelFactory(Of ICustomer) = New ChannelFactory(Of ICustomer)(myBinding, myEndPoint)
'Creating a Channel to access Services
Dim client As ICustomer = MychannelFactory.CreateChannel
lst = client.GetCustomerData()
grdCustomers.DataSource = lst
grdCustomers.DataBind()
End Sub
For Row Editing:
Protected Sub grdCustomers_RowEditing(sender As Object, e As GridViewEditEventArgs) Handles grdCustomers.RowEditing
grdCustomers.EditIndex = e.NewEditIndex
GetAllCustomersData()
End Sub
For Row Updating:
Protected Sub grdCustomers_RowUpdating(sender As Object, e As GridViewUpdateEventArgs)
Dim result As Boolean
Dim CustObj As New Services.Entities.Customers.Customer
CustObj.CustomerID = DirectCast(grdCustomers.Rows(e.RowIndex).FindControl("lblCustomerId"), Label).Text
CustObj.ContactName = DirectCast(grdCustomers.Rows(e.RowIndex).FindControl("txtContactName"), TextBox).Text
CustObj.City = DirectCast(grdCustomers.Rows(e.RowIndex).FindControl("ddlCity1"), DropDownList).SelectedValue.ToString
'Type of binding
Dim myBinding As New BasicHttpBinding
'Endpoint name defining
Dim myEndPoint As New EndpointAddress(ConfigurationManager.AppSettings("CustomerServiceUrl").ToString())
Dim myChannelFactory As ChannelFactory(Of ICustomer) = New ChannelFactory(Of ICustomer)(myBinding, myEndPoint)
'Creating a Channel to access Services
Dim client As ICustomer = myChannelFactory.CreateChannel
result = client.UpdateCustomerDetails(CustObj)
grdCustomers.EditIndex = -1
GetAllCustomersData()
End Sub
For Row Edit Cancel Button:
Protected Sub grdCustomers_RowCancelingEdit(sender As Object, e As GridViewCancelEditEventArgs)
grdCustomers.EditIndex = -1
GetAllCustomersData()
End Sub