I have a GridView with a buttonfield column that I am using to edit and save the value of records. The problem I am having is that in the Grid's Row Command event I want to change the button's text from "Edit" to "Save" but my code below doesn't work. Can anyone see what I'm doing wrong?
HTML:
Code behind:
HTML:
<asp:GridViewID="gvProducts"CssClass="gvOrders"Width="560px"PagerStyle-CssClass="pager"OnRowCommand="gvProducts_RowCommand"HeaderStyle-CssClass="header"RowStyle-CssClass="rows"AllowPaging="true"AutoGenerateColumns="false"runat="server"DataSourceID="ObjectDataSource1"AllowSorting="True"><Columns><asp:buttonfieldbuttontype="Button"HeaderStyle-BackColor="Transparent"commandname="Edit"headertext="Edit"text="Edit"/><asp:buttonfieldbuttontype="Button"HeaderStyle-BackColor="Transparent"commandname="Delete"headertext="Delete"text="Delete"/><asp:BoundFieldHeaderText="Product ID"DataField="ProductID"SortExpression="ProductID"/><asp:BoundFieldHeaderText="Units In Stock"DataField="UnitsInStock"SortExpression="UnitsInStock"/><asp:BoundFieldHeaderText="Units On Order"DataField="UnitsOnOrder"SortExpression="UnitsOnOrder"/><asp:BoundFieldHeaderText="Reorder Level"DataField="ReorderLevel"SortExpression="ReorderLevel"/></Columns></asp:GridView>
Code behind:
protectedvoid gvProducts_RowCommand(object sender, GridViewCommandEventArgs e) { switch (e.CommandName) { case"Edit": int index = Convert.ToInt32(e.CommandArgument); Button myButton = null; myButton = (Button)gvProducts.Rows[index].Cells[0].Controls[0]; myButton.Text = "Save"; return; case"Delete": return; default: return; } }