gridview删除选定行

pinkyll 2006-10-30 08:58:22
刚学习.net,在网上发现都是03版vs的例子,请问一下有没有05 gridview下删除选定行的代码学习一下,谢谢了
...全文
270 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
pinkyll 2006-10-31
  • 打赏
  • 举报
回复
我写了一个,但是运行没反应,大家帮忙看看在gridview里一列删除按钮,commandname=Delete;代码: protected void GridView1_RowDeleting1(object sender, GridViewDeleteEventArgs e)
{
string id = GridView1.DataKeys[e.RowIndex].Values[0].ToString();
string connStr = System.Configuration.ConfigurationManager.AppSettings["strConn"].ToString();
string SqlStr = "delete from news where id=" + id;



SqlConnection con = new SqlConnection(connStr);
con.Open();
DataSet myDataSet = new DataSet();
string sql = "select* from news where shifouchakan = 0";
SqlDataAdapter myCommand = new SqlDataAdapter(sql, con);

//填充DataSet
myCommand.Fill(myDataSet);

//关闭链接
GridView1.DataSource = myDataSet;

//绑定
GridView1.DataBind();

}
lxmfll2000 2006-10-31
  • 打赏
  • 举报
回复
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
string url = Request.Url.ToString();
if (null != Session["UserID"])
{
cSWUserId = Session["UserID"].ToString();
}
if (e.CommandName == "DeleteTheRecord")
{
Int32 startindex = Convert.ToInt32(e.CommandArgument);
DataKey keyValue = GridView1.DataKeys[startindex];
Int32 hubId = Convert.ToInt32(keyValue[0]);
Int32 appointmentId = Convert.ToInt32(keyValue[1]);
string clientid = keyValue[2].ToString();
Int32 doctorTypeID = Convert.ToInt32(keyValue[3]);
//执行删除操作
bFPHN.UpdatePhnAlert(cSWUserId, hubId, appointmentId, doctorTypeID);
}
}
供参考
孟子E章 2006-10-31
  • 打赏
  • 举报
回复
http://dotnet.aspx.cc/article/A8EFC285-F0B1-4F8F-8E73-2B7D8724A47C/read.aspx
localway 2006-10-31
  • 打赏
  • 举报
回复
dataGridView1.Rows.RemoveAt和Remove都行呀。
pinkyll 2006-10-31
  • 打赏
  • 举报
回复
我试了一下,不行啊,用过的能不能举例说明一下,谢谢!
kinghawk 2006-10-30
  • 打赏
  • 举报
回复
DataGridView.Rows[index]有删除方法
程序的色彩 2006-10-30
  • 打赏
  • 举报
回复
和VS2003使用的方法一样啊。顶先!

111,092

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧