
gridview控件中buttonfield的使用问题
在GRIDVIEW控件中添加了一个buttonfield字段,但不知道这个怎么用。我把它的CommandName设置成了delete。HeaderText设置成“删除”。...
在GRIDVIEW控件中添加了一个buttonfield字段,但不知道这个怎么用。我把它的CommandName设置成了delete。HeaderText设置成“删除”。它要实现的作用是点一下就把本行(本条记录)删除。要怎么实现?
GridView有一个两个方法为Rowdeleted和Rowdeleting.好像把这两个方法直接用来删除记录的。但是我不太会用 展开
GridView有一个两个方法为Rowdeleted和Rowdeleting.好像把这两个方法直接用来删除记录的。但是我不太会用 展开
2个回答
展开全部
protected void grdProgram_RowCommand(object sender, GridViewCommandEventArgs e)
{
int index = Int32.Parse(e.CommandArgument.ToString());
string _bookid = grdProgram.Rows[index].Cells[2].Text;
if (e.CommandName == "Delete")
{
DataSet ds = operation.getDataSet("delete from book where BookId='" + _bookid+"'");
grdDatabase.DataSource = ds;
grdDatabase.DataBind();
}
}
要有这个方法!
自己试着改下 这例子可以运行!
{
int index = Int32.Parse(e.CommandArgument.ToString());
string _bookid = grdProgram.Rows[index].Cells[2].Text;
if (e.CommandName == "Delete")
{
DataSet ds = operation.getDataSet("delete from book where BookId='" + _bookid+"'");
grdDatabase.DataSource = ds;
grdDatabase.DataBind();
}
}
要有这个方法!
自己试着改下 这例子可以运行!
展开全部
<asp:GridView id="Grid_Product" runat="server" Width="100%" CssClass="zt12" OnRowDeleting="Grid_Product_RowDeleting"
<asp:TemplateField ShowHeader="False"><ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete"
Text="删除"></asp:LinkButton>
</ItemTemplate>
/// <summary>
/// 删 除
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid_Product_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
Model.Db_Product DelPro = new Model.Db_Product();
GridViewRow gr = Grid_Product.Rows[e.RowIndex];
DelPro.ID = int.Parse(((Label)gr.FindControl("lblid")).Text);
Bll.Productlist.ProductDel(DelPro);
BindProductList(this.PageControlDigital2_1.CurrentPageIndex);
}
<asp:TemplateField ShowHeader="False"><ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete"
Text="删除"></asp:LinkButton>
</ItemTemplate>
/// <summary>
/// 删 除
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid_Product_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
Model.Db_Product DelPro = new Model.Db_Product();
GridViewRow gr = Grid_Product.Rows[e.RowIndex];
DelPro.ID = int.Parse(((Label)gr.FindControl("lblid")).Text);
Bll.Productlist.ProductDel(DelPro);
BindProductList(this.PageControlDigital2_1.CurrentPageIndex);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询