Solved

ASP.NET gridview delete linkbutton

Posted on 2012-04-05
1
526 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

862 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

22 Experts available now in Live!

Get 1:1 Help Now