GridView删除前确认

代码
<asp:GridView ID="gvProduct" runat="server" AutoGenerateColumns="False" CssClass="grid-view"
Width
="100%" onrowcommand="gvProduct_RowCommand"
onrowdatabound
="gvProduct_RowDataBound" onrowdeleting="gvProduct_RowDeleting">
<RowStyle CssClass="normal" />
<Columns>
<asp:BoundField DataField="Code" HeaderText="产品条码" />
<asp:BoundField DataField="ProductName" HeaderText="产品名称" />
<asp:BoundField DataField="Goods" HeaderText="货号" />
<asp:BoundField DataField="ColorName" HeaderText="花色" />
<asp:BoundField DataField="Spec" HeaderText="规格" />
<asp:BoundField DataField="Qty" HeaderText="数量" />
<asp:BoundField DataField="Price" HeaderText="单价" />
<asp:BoundField DataField="SumMoney" HeaderText="结算金额" />
<asp:TemplateField HeaderText="删除" ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="lbtnDelete" runat="server" CausesValidation="False" CommandName="Delete"
Text
="删除" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" ></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle CssClass="header" />
<AlternatingRowStyle CssClass="alternate" />
</asp:GridView>

 

 

代码
protected void gvProduct_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton lbtnDelete
= (LinkButton)e.Row.Cells[8].FindControl("lbtnDelete");
string goods = e.Row.Cells[2].Text.ToString();
string qty = e.Row.Cells[5].Text.ToString();
lbtnDelete.OnClientClick
= string.Format("return confirm('是否要删除产品{0}数量{1}?');", goods, qty);
}
}

 

 

代码
protected void gvProduct_RowCommand(object sender, GridViewCommandEventArgs e)
{
string command = e.CommandName;
if (command == "Delete")
{
#region 删除
int rowIndex = Convert.ToInt32(e.CommandArgument);
DataTable dt
= (DataTable)Session[WebUtility.SessionName.DtOrderDetail.ToString()];
dt.Rows.RemoveAt(rowIndex);
Session[WebUtility.SessionName.DtOrderDetail.ToString()]
= dt;
BindOrderMaster();
BindOrderDetail();
#endregion
}
}

 

 

 

 



posted on 2010-08-09 12:58  NewSunshineLife  阅读(522)  评论(3编辑  收藏  举报

导航