怎么点击页面上的删除按钮,执行Griview中每行复选框选中项的删除操作?
解决方案 »
- 问号传值的问题.
- DateTime.Now 赋值给 DateTime 的变量,产生的sql语句时间格式突然变成7位毫秒了
- 页面定向
- 请教学习.net的方法
- datagrid中动态生成的一列必须用textbox显示数据(需绑定数据库得到)
- 怎样在ASP.NET程序中使用(.resources)资源文件
- 谁能告知csdn左边的树是怎么做的,/expert/deeptree/css/deeptree.css文件下载不了,那位大虾有给我mail一份
- 水晶报表样式加载不到web页面,水晶报表打印功能
- 使用DataReader填充DataGrid的问题
- 如何触发事件?
- Formview 问题
- asp.net 关于动态设置数据验证器的比较值问题
{
string rightCode=""; foreach (GridViewRow gvr in this.GridView1.Rows)
{
CheckBox chk = (CheckBox)gvr.FindControl("CheckBox1");
if (chk.Checked)
{
//删除
}
}
}hehe
{
List<int> lst = new List<int>();
foreach (GridViewRow gr in this.gvNews.Rows)
{
if (((CheckBox)gr.FindControl("CheckBox1")).Checked)
lst.Add(int.Parse(((HiddenField)gr.FindControl("Hd_Id")).Value));
}
foreach (int i in lst)
{
//删除
}
BindData();//绑定数据
}
有什么用?
本人自学。见笑了
<ItemTemplate>
<asp:CheckBox ID="chkSelected" runat="server" Checked="False" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="用户ID">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("UserID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
后台: protected void ImageButtonDelete_Click(object sender, ImageClickEventArgs e)
{
for (int i = 0; i < this.GridView1.Rows.Count; i++)
{
bool isChecked = ((CheckBox)GridView1.Rows[i].FindControl("chkSelected")).Checked;
if (isChecked)
{
string userID = ((Label)GridView1.Rows[i].FindControl("Label1")).Text;
Users user = new Users();
user.DeleteByProc(userID)) //根据userID删除它 }
}
GridViewBind(); //重新绑定GridView
}
datagirdview删除数据
在datagirdview的CLICK事件中写
string productID=this.datagirdview.SelectedCell[0].value.ToString();//返回第一列 根据id来删除 在之前要定义private String productID
在按钮的click事件中写
DialogResult answer=MessageBox.Show("确定删除吗","删除操作",MessageBoxButtons.YesNo);
if(answer == DialogResult .Yes)
{
int cuont=this.deleteProduct(productID);
MessageBox.Show("删除行数:"+count.ToString());
}
private int deleteProduct(string id)
{
int count=0;
//打开connection
//定义一个SQL语句
//定义一个command
//用command对象执行语句
//关闭connection
string sql="delete from products where id =" +id;
SqlCommand comm=new SqlCommand(sql.con);
con.open();
count=comm.ExecuteNonQuery();
con.Close();
return count;
}