在控件的属性栏“事件”中有EditCommand/DeleteCommand/CancelCommand 事件的,双击添加你的代码,按钮就做你要它做的事情了。
解决方案 »
- repeater 中如何实现 单选
- 网站覆盖后第一次打开有时候会很慢?
- iis设置的问题
- 通过Response返回文件,如何实现下载限速?
- 如何查看客户端在浏览哪一个页面
- access连接串在web.config中该怎样写
- 一个关于DataGrid的菜鸟问题,请大家帮帮忙呀!!!
- 这个目录是做什么的C:\Documents and Settings\[your computer name]\ASPNET\Local Settings\Temp\
- asp.net+win2000 pro调试的问题?
- 我的页面上有Label1~Label100,怎么通过给定一个值来显示给定的个数
- 如何分别动态地设置下拉菜单的value和显示值?
- 用户自定义控件如何访问Session值?
{
string SQLStatement="DELETE from sys_select where code = @code" ; //通过主键列code删除
string myConnectionString = ConfigurationSettings.AppSettings["ConnectString"];
SqlConnection myConnection = new SqlConnection(myConnectionString);
SqlCommand myCommand = new SqlCommand (SQLStatement,myConnection);
myCommand.Parameters.Add(new SqlParameter("@code", SqlDbType.VarChar ,20));
myCommand.Parameters["@code"].Value = MyDataGrid.DataKeys[(int)e.Item.ItemIndex]; //取得选中行的主键值
myCommand.CommandTimeout = 15;
myCommand.CommandType=CommandType.Text; try
{
myConnection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();
BindGrid();
}
catch
{ if(MyDataGrid.CurrentPageIndex>=MyDataGrid.PageCount) //控制最后一条纪录删除不出错
{
int i=MyDataGrid.CurrentPageIndex;
i--;
MyDataGrid.CurrentPageIndex=i;
BindGrid();
}
}
// MyDataGrid.EditItemIndex = -1;
// BindGrid();
}