Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
hi i have a datagridview and i need to add a delete button in the datagridview which will delete that particular row from the database...i need to know how is it possible to add the delete button in a col in the datagridview.
Thanks
Posted
Comments
[no name] 29-Nov-11 0:45am    
so you need the code to insert a button inside gridview of asp.net? did you mean gridview or datagridview?
Dunstan89 29-Nov-11 1:04am    
datagridview....sorry if i didnt mention it, but im building a windowsform application
[no name] 29-Nov-11 1:36am    
try my solution

For datagridview,

try this one:
C#
DataGridViewButtonColumn btn = new DataGridViewButtonColumn();
dataGridView1.Columns.Add(btn);
btn.HeaderText = "Click Data";
btn.Text = "Click Here";
btn.Name = "btn";
btn.UseColumnTextForButtonValue = true;


Please mark as answer and vote 5 if this solved your problem

Regards,
Eduard
 
Share this answer
 
v2
Comments
Dunstan89 29-Nov-11 3:38am    
thanks for ur help...i jus need to know how to get that particular row index for which the deleted butto is clicked
in the properties of the gridview, set
C#
AutoGenerateDeleteButton = true


hope it helps!

don't to forget to vote,,

thanks
 
Share this answer
 
Comments
Manoj K Bhoir 29-Nov-11 1:35am    
There is no property in DataGridView like AutoGenerateDeleteButton.Please check this.
If inserting a button is your only problem, then try adding these lines into your gridview columns

XML
<asp:CommandField SelectText="DELETE" ShowSelectButton="True" ItemStyle-Width="50px"
                        ButtonType="Button">
                        <ItemStyle Width="50px" />
                    </asp:CommandField>


Regards,
Eduard
 
Share this answer
 
To delete any row or record therer is no need of delete button.

You can Delete any row by selecting it and pressing Delete Button on your KeyBord.Brfore doing this just check that ther following property of DataGridView should be True

VB
AllowUserToDeleteRows = True

I hope it will help you :)
 
Share this answer
 
v2
 
Share this answer
 
Comments
CHill60 22-Jul-13 18:02pm    
You really seem to like posting answers to old questions with links to articles by Lakshmi tulasi - friend of yours? Be aware that this behaviour usually just attracts downvotes

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900