Solved

Gridview delete button event

Posted on 2008-10-10
7
578 Views
Last Modified: 2012-06-27
I've a gridview with a delete button on each row. When I click the button on a row, I want to delete that row from the Gridviewand from the database. The Gridview is bound to a table of my access database. Below you can find the code of my Gridview.

Thanks,

jppinto
<asp:GridView ID="grdAbsentismo" runat="server" AutoGenerateColumns="False" DataSourceID="GridDataSource" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" CellPadding="4" ForeColor="#333333">

                <Columns>

                    <asp:BoundField DataField="Empregado" HeaderText="Empregado" SortExpression="Empregado">

                        <ItemStyle HorizontalAlign="Center" Width="150px" />

                    </asp:BoundField>

                    <asp:BoundField DataField="Motivo" HeaderText="Motivo" SortExpression="Motivo">

                        <ItemStyle HorizontalAlign="Center" Width="180px" />

                    </asp:BoundField>

                    <asp:BoundField DataField="MotivoLei" HeaderText="Detalhe Absentismo" SortExpression="MotivoLei">

                        <ItemStyle HorizontalAlign="Center" Width="200px" />

                    </asp:BoundField>

                    <asp:BoundField DataField="DataInicio" HeaderText="Data de Inicio" SortExpression="DataInicio" DataFormatString="{0:dd/MM/yyyy}">

                        <ItemStyle HorizontalAlign="Center" Width="90px" />

                    </asp:BoundField>

                    <asp:BoundField DataField="Dias" HeaderText="N&#186; Dias" SortExpression="Dias">

                        <ItemStyle HorizontalAlign="Center" Width="60px" />

                    </asp:BoundField>

                    <asp:ButtonField ButtonType="Button" Text="Remover">

                        <ItemStyle HorizontalAlign="Center" Width="100px" />

                    </asp:ButtonField>

                </Columns>

                <HeaderStyle BackColor="#5D7B9D" BorderStyle="Solid" BorderWidth="1px" Height="25px" Font-Bold="True" ForeColor="White" />

                <RowStyle BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" Height="25px" BackColor="#F7F6F3" ForeColor="#333333" HorizontalAlign="Left" />

                <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

                <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />

                <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />

                <EditRowStyle BackColor="#999999" />

                <AlternatingRowStyle BackColor="White" ForeColor="#284775" />

            </asp:GridView>

            <asp:AccessDataSource ID="GridDataSource" runat="server" DataFile="~/db/manpower.mdb"

                SelectCommand="SELECT [Empregado], [Motivo], [DataInicio], [Dias], [MotivoLei] FROM [Absentismo]" CacheExpirationPolicy="Sliding"></asp:AccessDataSource>

Open in new window

0
Comment
Question by:jppinto
7 Comments
 
LVL 20

Expert Comment

by:informaniac
ID: 22685955
You'll have to configure a delete command for the accessdatasource
0
 
LVL 16

Expert Comment

by:Gyanendra Singh
ID: 22685979
supported to informaniac comment .. need to add this in access datasource
 DeleteCommand="DELETE FROM xxxx
                 WHERE ID=@ID"

also need to add DataKeyNames in your grid control so as per sample it would be
<asp:GridView ID="grdAbsentismo" runat="server" DataKeyNames="ID"  AutoGenerateColumns="False" DataSourceID="GridDataSource" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" CellPadding="4" ForeColor="#333333">
0
 
LVL 33

Author Comment

by:jppinto
ID: 22686113
Can you be more explicit please? I've started using ASP just a few days ago...

Thanks,

jppinto
0
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.

 
LVL 20

Expert Comment

by:informaniac
ID: 22686139
0
 
LVL 48

Accepted Solution

by:
jpaulino earned 500 total points
ID: 22686303
The easy way (I think) is to remove that buttonfield and add a command field(delete). Then change the "delete" text to "remover" and the button type to "button" (instead of link)
Don't forget you need to have a primary key field!
0
 
LVL 33

Author Comment

by:jppinto
ID: 22689088
I've tryed the solution presented by jpaulino and it seem to be the simplest solution for what I need to do.

Thanks,

jppinto
0
 
LVL 33

Author Closing Comment

by:jppinto
ID: 31504970
Simple solution. Good work!
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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

911 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