简体   繁体   English

如何使用C#从asp.net中的datagrid控件中删除行?

[英]how to remove row from datagrid control in asp.net using c#?

I have created a datagrid in asp.net and it loads the data.I need to remove the data on 我已经在asp.net中创建了一个数据网格并加载了数据。我需要删除数据

OnItemCommand event. OnItemCommand事件。

So anybody knows this,help me. 所以任何人都知道这一点,请帮助我。

you can see this Link 你可以看到这个链接

http://www.aspdotnet-suresh.com/2011/02/how-to-inserteditupdate-and-delete-data.html http://www.aspdotnet-suresh.com/2011/02/how-to-inserteditupdate-and-delete-data.html

 protected void gvDetails_RowDeleting(object sender, GridViewDeleteEventArgs e)
 {
     int userid =Convert.ToInt32(gvDetails.DataKeys[e.RowIndex].Values["UserId"].ToString());
     string username = gvDetails.DataKeys[e.RowIndex].Values["UserName"].ToString();
     con.Open();
     SqlCommand cmd = new SqlCommand("delete from Employee_Details where UserId=" +userid, con);
     int result = cmd.ExecuteNonQuery();
     con.Close();
     if (result == 1)
     {
    BindEmployeeDetails();
    lblresult.ForeColor = Color.Red;
    lblresult.Text = username + " details deleted successfully";
     }
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在asp.net 2.0 C#中查找datagrid行 - how to find datagrid row in asp.net 2.0 C# 如何从asp.net中的datagrid删除行 - How to remove row from datagrid in asp.net 使用C#在ASP.NET中的DataGrid - DataGrid in asp.net using c# 如何使用C#将特定asp.net控件(如文本框,标签等),图表控件图像和数据网格中的文本导出到Powerpoint - how to export text in specific asp.net control like textbox,label etc, chart control image and datagrid to powerpoint using c# 如何使用c#从asp.net中的datagrid获取选定的列值或名称 - how to get selected column value or name from datagrid in asp.net using c# 在Asp.net C#的ItemDataBound上找不到DataGrid的第一行 - First row of DataGrid is not finding on ItemDataBound in Asp.net c# 如何在不使用ASP.NET服务器端控件的情况下从C#ASP.NET中读取HTML文件类型的输入流 - How to read inputstream from HTML file type in C# ASP.NET without using ASP.NET server side control 如何从asp.net c#中的url中删除“.aspx”? - How to remove “.aspx” from url in asp.net c#? 如何使用C#从数据库创建ASP.Net图表控件 - How to Create ASP.Net Chart Control from Database using C# 使用 asp.net c# 将大的 asp.net 控件数据按行插入 sql 表 - Insert large asp.net control data row wise into sql table using asp.net c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM