.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> Windows Application >> Post New QuestionBookmark and Share Subscribe to Forum

how to delete row of datagridview on delete button press?

Posted By: krishana singh     Posted Date: December 29, 2010    Points:2   Category :Windows Application
how to delete row of datagridview on delete button press?

Responses
Author: Karthikeyan Anbarasan       [Moderator]      
Posted Date: December 29, 2010     Points: 5   

use the below code in data bound to check and delete

LinkButton l = (LinkButton)e.Row.FindControl("LinkButton1");
l.Attributes.Add("onclick", "javascript:return " +
"confirm('Are you sure you want to delete this record " +
DataBinder.Eval(e.Row.DataItem, "ID") + "')");


Thanks
Karthik
http://www.f5debug.net
Mark as Answer if the answer solves your issue!!!
Author: Syed Shakeer Hussain             
Posted Date: December 31, 2010     Points: 5   

Hi,
Double click your DataGrid and write the code to get selected Row :-

int empid ;
Private void dataGridView1_CellContentClick_1(objectsender,DataGridViewCellEventArgs e)
{
i = dataGridView1.SelectedCells[0].RowIndex;
empid = dataGridView1.Rows[i].Cells[0].Value.ToString();
}


Write the below code in Delete Button

SqlCommand cmd=new SqlCommand("Delete * from Emp where empid="+empid+"",conn);
cmd.ExecuteNonQuery();
//write again DataGrid Bind code here




Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend