Solved

ASP.NET gridview Edit LinkButton

Posted on 2012-04-09
4
453 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

895 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now