I have a basic gridview to which I am binding the data from the code behind from a SQL stored procedure.
<asp:GridView ID="gvCheckResults" runat="server"
OnRowDataBound="gvCheckResults_RowDataBound"
RowStyle-CssClass="gridViewRow"
CssClass="gridView"
AlternatingRowStyle-CssClass="gridViewAlternatingRow"
HeaderStyle-CssClass="gridViewHeader">
</asp:GridView>
Databind:
gvCheckResults.DataSource = dataContext.GetResults(Name, Address);
gvCheckResults.DataBind();
if (!IsPostBack)
{
//Add Edit column.
CommandField cField = new CommandField();
cField.EditText = "Edit";
cField.ShowEditButton = true;
gvCheckResults.Columns.Insert(0, cField);
}
How can I programmatically add Edit button to each result row?
I know how to do it when the datasource object is setup in the aspx page, but never done it programmatically.
Best Answer
Try Like this
OnRowEditEvent()
set the gridview edit index toe.newrowindex
and bind it again like this.