?
Solved

ASP.NET gridview delete linkbutton

Posted on 2012-04-05
1
Medium Priority
?
533 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 16

Accepted Solution

by:
Vikram Singh Saini earned 2000 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

764 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