How to edit a asp.net gridview row.

newjeep19
newjeep19 used Ask the Experts™
on
I need to know how to edit a asp.net gridview row when it has been uploaded from an excel spreadsheet but has not been saved to a SQL database. I want to give the option to the user to edit and delete rows in the gridview table after they have uploaded the table from excel file before they submit the gridview to the SQL database.
Please help.
Thank you,
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2010
Commented:
For each of your ItemTemplate tags in the gridview, add an EdittItemTemplate tag.  And then add a column with the edit and delete buttons.  For example:

<ItemTemplate>
     <tr>
        <td><%# Eval("FirstName") %></td>
     </tr>
</ItemTemplate>
 <EditItemTemplate>
      <tr>
        <td><asp:TextBox runat="server" ID="txtFirstName" CssClass="text" style="width:76px;" MaxLength="50" Text='<%# Eval("FirstName") %>'/></td>
     </tr>
</EditItemTemplate>
<asp:CommandField ButtonType="Link" ShowEditButton="true" ShowDeleteButton="true" ItemStyle-Width="150"/>

Open in new window

Author

Commented:
My asp.net gridview is dynamic see the code below:
<asp:GridView ID="gvNew" runat="server"
                                OnSelectedIndexChanged="gvNew_SelectedIndexChanged"
                                OnRowEditing="EditCustomer"
                                OnRowUpdating="UpdateScoreCard"
                                OnRowCommand="gvGetExsistingPromo_RowCommand"
                                ShowFooter="true"
                                OnRowCancelingEdit="CancelEdit">
                                <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
                                <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
                                <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
                                <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
                                <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" Height="75px" HorizontalAlign="Center" VerticalAlign="Middle" />
                                <AlternatingRowStyle BackColor="#F7F7F7" />
                                <Columns>
                                    <%--<asp:BoundField DataField="Name" HeaderText="Name" ItemStyle-Width="150" />
                                    <asp:BoundField DataField="Country" HeaderText="Country" ItemStyle-Width="150" />--%>
                                    <asp:TemplateField>
                                        <ItemTemplate>
                                            <asp:ImageButton ID="btnedit" runat="server" CommandName="Edit" ImageUrl="~/images/Edit.png" Width="50px" Visible="true" CommandArgument="<%# Container.DataItemIndex %>" />
                                        </ItemTemplate>
                                        <EditItemTemplate>
                                                                                       <asp:ImageButton ID="imgAddBtn" runat="server" Width="50px" ImageUrl="~/images/addfixed.png" OnClientClick="imgAddBtn_Click" />
                                                                                   </EditItemTemplate>
                                    </asp:TemplateField>
                                    <%--<Delete Button>--%>
                                    <asp:TemplateField>
                                        <ItemTemplate>
                                            <asp:ImageButton ID="imgDeleteBtn" runat="server" Width="50px" ImageUrl="~/images/Delete.png" OnClientClick="return confirm('Do you want to delete?')" CausesValidation="False" CommandName="Delete" Visible="true" ToolTip="Send an email to the course attendees"></asp:ImageButton>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                </Columns>
                            </asp:GridView>

Open in new window

Author

Commented:
Any thoughts on this? Please help!
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

Jitendra PatilSr.Software Engineer
Top Expert 2013
Commented:
you can try providing  a popup  for editing row values, showing the selected row for edit on edit click,
on the row command event  get the id of the row Or the record, get the latest changes provided by the user and update the same in datatable or dataset and again rebind the grid.

hope this helps.
I found a way to edit the gridview by using asp.net place holder

Author

Commented:
I found a way using asp.net place holder.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial