Solved

ASP.NET gridview delete linkbutton

Posted on 2012-04-05
1
527 Views
Last Modified: 2012-04-06
I have an ASP.NET GridView that has a LinkButton field for a Delete option on the GridView for each row.  However when I click the Delete LinkButton on the Gridview, it does not do anything.  I have a DELETE command specified on the DataSource that is associated with the Gridview.  I just can't figure out why the Delete command will not fire.  Here is the GridView's code:


<asp:GridView ID="VersionGridView" runat="server" AllowPaging="True"
            AutoGenerateColumns="False" BackColor="White" BorderColor="#E7E7FF"
            BorderStyle="None" BorderWidth="1px" CellPadding="3" DataKeyNames="Id"
            DataSourceID="VersionDataSource" EmptyDataText="No versions."
            onrowcreated="VersionGridView_RowCreated"
            OnRowDeleting="VersionGridView_RowDeleting" PageSize="5"
            style="margin-left: 18px" Width="567px"
            onrowdatabound="VersionGridView_RowDataBound" >
            <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
            <Columns>
                    <asp:TemplateField>
                    <ItemTemplate>
                            <asp:LinkButton ID="LinkButtonDelete" CommandName="Delete" Text="Delete" runat="server"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
            <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
            <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
            <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
            <AlternatingRowStyle BackColor="#F7F7F7" />
        </asp:GridView>
0
Comment
Question by:zintech
1 Comment
 
LVL 16

Accepted Solution

by:
Vikram Singh Saini earned 500 total points
ID: 37813104
1. Share your DataSource code too.

2. Is AutoEventWireup is set to true in Page directive?

<%@ Page Title="" Language="C#" AutoEventWireup="true"%>

3. Match your code with following:

 <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="false"
            DataKeyNames="Id" EmptyDataText="There are no data records to display."
            CssClass="grid" AllowSorting="false">           
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:LinkButton ID="LinkButtonDelete" CommandName="Delete" Text="Delete" runat="server">
                        </asp:LinkButton></ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:conString %>"
            DeleteCommand="DELETE FROM [tableName] WHERE [Id] = @Id" >           
            <DeleteParameters>
                <asp:Parameter Name="Id" Type="Int32" />
            </DeleteParameters>
        </asp:SqlDataSource>

Open in new window

0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

786 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