Solved

ASP.NET gridview delete linkbutton

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
.net VBA word safemode 1 24
C# Reverse int in fast ways 6 28
Chat Room 1 30
Get list of word ducuments in a folder 10 21
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
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…

747 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

15 Experts available now in Live!

Get 1:1 Help Now