dev GridControl中的GridView怎么实现批量删除、修改GridView表中的任意数据后保存。求大神解决
主要问题如题,还有就是怎么获取用户输入的数据(就是表中最后1行是空的,可让用户添加新的数据行)。,谢谢了,如果好的话可再加分。。有源码的也可发617942014@qq.c...
主要问题如题,还有就是怎么获取用户输入的数据(就是表中最后1行是空的,可让用户添加新的数据行)。,谢谢了,如果好的话可再加分。。有源码的也可发617942014@qq.com
展开
展开全部
批量删除好解决,选中GridView右上角的编辑添加模板列,选中ItemTemplate在里面拉一个复选框控件然后就是判断复选框是否是选中状态如果是循环删除选中的数据列。修改的话就点编辑列在可用字段里有一个CommandField列点击他展开编辑,更新,取消这一行就点击添加至于编辑更新取消这个有点儿麻烦意识说不清,我就直接给你贴代码了 #region 编辑事件
protected void gvBooks_RowEditing(object sender, GridViewEditEventArgs e)
{
//设定选中行
gvBooks.EditIndex = e.NewEditIndex;
//重新绑定数据
HRDataBind();
//获取选中行的下拉框控件
DropDownList ddl = (DropDownList)gvBooks.Rows[e.NewEditIndex].FindControl("ddlCate");
//查询绑定数据
ddl.DataSource = cm.GetAllCategories();
ddl.DataTextField = "Name";
ddl.DataValueField = "Id";
ddl.DataBind();
//查询隐藏列
HiddenField hf = (HiddenField)gvBooks.Rows[e.NewEditIndex].FindControl("hfCateId");
ddl.SelectedValue = hf.Value;
}
#endregion
#region 取消编辑
protected void gvBooks_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
//GV恢复正常状态
gvBooks.EditIndex = -1;
//重新绑定数据
HRDataBind(); ;
}
#endregion
#region 更新
protected void gvBooks_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//获取图书Id
int id = Convert.ToInt32(gvBooks.DataKeys[e.RowIndex].Value);
//图书名
string title = ((TextBox)gvBooks.Rows[e.RowIndex].FindControl("txtTitle")).Text;
//作者
string author = ((TextBox)gvBooks.Rows[e.RowIndex].FindControl("txtAuthor")).Text;
//类别id
DropDownList ddl = (DropDownList)gvBooks.Rows[e.RowIndex].FindControl("ddlCate");
int cateId = Convert.ToInt32(ddl.SelectedValue);
//根据Id查询book
Books book = bm.QueryBookById(id);
book.Title = title;
book.Author = author;
book.Categories = new Categories() { Id = cateId };
//更新
bm.UpdateBook(book);
//更新完成恢复正常状态
gvBooks.EditIndex = -1;
HRDataBind();
}
#endregion
#region 删除
protected void gvBooks_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
//获取id
int id = Convert.ToInt32(gvBooks.DataKeys[e.RowIndex].Value);
//删除
bm.DeleteBook(id);
//重新绑定
HRDataBind();
}
#endregion
protected void gvBooks_RowEditing(object sender, GridViewEditEventArgs e)
{
//设定选中行
gvBooks.EditIndex = e.NewEditIndex;
//重新绑定数据
HRDataBind();
//获取选中行的下拉框控件
DropDownList ddl = (DropDownList)gvBooks.Rows[e.NewEditIndex].FindControl("ddlCate");
//查询绑定数据
ddl.DataSource = cm.GetAllCategories();
ddl.DataTextField = "Name";
ddl.DataValueField = "Id";
ddl.DataBind();
//查询隐藏列
HiddenField hf = (HiddenField)gvBooks.Rows[e.NewEditIndex].FindControl("hfCateId");
ddl.SelectedValue = hf.Value;
}
#endregion
#region 取消编辑
protected void gvBooks_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
//GV恢复正常状态
gvBooks.EditIndex = -1;
//重新绑定数据
HRDataBind(); ;
}
#endregion
#region 更新
protected void gvBooks_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//获取图书Id
int id = Convert.ToInt32(gvBooks.DataKeys[e.RowIndex].Value);
//图书名
string title = ((TextBox)gvBooks.Rows[e.RowIndex].FindControl("txtTitle")).Text;
//作者
string author = ((TextBox)gvBooks.Rows[e.RowIndex].FindControl("txtAuthor")).Text;
//类别id
DropDownList ddl = (DropDownList)gvBooks.Rows[e.RowIndex].FindControl("ddlCate");
int cateId = Convert.ToInt32(ddl.SelectedValue);
//根据Id查询book
Books book = bm.QueryBookById(id);
book.Title = title;
book.Author = author;
book.Categories = new Categories() { Id = cateId };
//更新
bm.UpdateBook(book);
//更新完成恢复正常状态
gvBooks.EditIndex = -1;
HRDataBind();
}
#endregion
#region 删除
protected void gvBooks_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
//获取id
int id = Convert.ToInt32(gvBooks.DataKeys[e.RowIndex].Value);
//删除
bm.DeleteBook(id);
//重新绑定
HRDataBind();
}
#endregion
更多追问追答
追问
这个GridView是第三方控件的,不是VS里面的那个~
追答
哦 还不一样吗 第三方控件都是有使用说明的 你仔细看看呗
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询