Solved

ASP.NET gridview Edit LinkButton

Posted on 2012-04-09
4
456 Views
Last Modified: 2012-04-13
I have a GridView that has a Delete and Edit LinkButtons at the end of every row.  What I want to get accomplished is that when the user clicks the Edit LinkButton, that they will then be able to edit any of the values in the selected row they chose to Edit, and then the Edit LinkButton will then read "Update" and when the user clicks Update it will execute the UPDATE statement on the DataSource that is specified for the GridView
0
Comment
Question by:zintech
4 Comments
 

Author Comment

by:zintech
ID: 37823115
Here is the code for the GridView right now.  Nothing happens when I click the Edit LinkButton.

<asp:GridView ID="GridView1" runat="server" oreColor="#333333" AutoGenerateColumns="False"
            DataKeyNames="Id" DataSourceID="DataSource1"
            EnableModelValidation="True" AllowSorting="True" Width="468px"
            onrowdatabound="GridView1_RowDataBound">
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <Columns>
                <asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False"
                    ReadOnly="True" SortExpression="Id" Visible="False" />
                <asp:BoundField DataField="ProjectId" HeaderText="ProjectId"
                    SortExpression="ProjectId" Visible="False" />
                <asp:BoundField DataField="VersionId" HeaderText="VersionId"
                    SortExpression="VersionId" Visible="False" />
                <asp:BoundField DataField="WBS" HeaderText="WBS" ItemStyle-Wrap="false"
                    SortExpression="WBS" />
                <asp:BoundField DataField="WBSTitle" HeaderText="WBSTitle" ItemStyle-Wrap="false"
                    SortExpression="WBSTitle" />
            <asp:TemplateField ItemStyle-Wrap="false">
                    <ItemTemplate>
                            <asp:LinkButton ID="LinkButtonDelete" CausesValidation="false" CommandName="Delete" Text="Delete" runat="server"></asp:LinkButton>
                            <asp:linkbutton id="btnEdit" runat="server" commandname="Edit" text="Edit" />  
                    </ItemTemplate>
                     <edititemtemplate>  
                                        <asp:linkbutton id="btnUpdate" runat="server" commandname="Update"
 text="Update" />  
                                        <asp:linkbutton id="btnCancel" runat="server" commandname="Cancel"
 text="Cancel" />  
                                </edititemtemplate>
                </asp:TemplateField>
            </Columns>
             <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                                      <PagerStyle HorizontalAlign="Center" BackColor="#284775" ForeColor="White" />
                                                      <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                                                      <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                                      <EditRowStyle BackColor="#999999" />
                                                      <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        </asp:GridView>
0
 
LVL 38

Expert Comment

by:Tom Beck
ID: 37823199
This is a common requirement of a GridView. There are tons of examples online for the proper way to set up that functionality. You are primarily missing the event handlers for OnRowEditing, OnRowUpdating, etc. Look here:

http://devilswork.wordpress.com/2009/03/27/gridview-row-edit-delete-and-update/
0
 
LVL 5

Expert Comment

by:Vishal Kedar
ID: 37826463
0
 
LVL 8

Accepted Solution

by:
Ashutosh Vyas earned 500 total points
ID: 37826505
http://aspsnippets.com/Articles/GridView---Add-Edit-Update-Delete-and-Paging-the-AJAX-way.aspx

This also explains you a way to insert new records to the same grid
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question