Solved

ASP.NET gridview Edit LinkButton

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video discusses moving either the default database or any database to a new volume.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

757 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

20 Experts available now in Live!

Get 1:1 Help Now