时间:2021-07-01 10:21:17 帮助过:35人阅读
<asp:Button ID="ButtonDelete" Text="Delete" runat="Server" OnClick="ButtonDelete_Click"
CausesValidation="false" />
<asp:GridView ID="GvCutterType" runat="server" DataKeyNames="CutterTypeId" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemStyle BorderWidth="1" BorderColor="#c0c0c0" Width="1%" />
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" onclick="Javascript:changeRowBgColor(this)" />
</ItemTemplate>
</asp:TemplateField>
<!--
other column templateField
-->
</Columns>
</asp:GridView>
xxx.aspx.cs:
代码如下:
protected void Page_Load(object sender, EventArgs e)
{
this.ButtonDelete.Attributes.Add("onclick", "return ConfirmOnDelete();");
}
protected void ButtonDelete_Click(object sender, EventArgs e)
{
//do delete something
}
Javascript:
代码如下:
function ConfirmOnDelete() {
if (document.getElementById("<%= GvCutterType.ClientID %>") == null) {
return false;
}
var objgv = document.getElementById("<%= GvCutterType.ClientID %>");
var rc = objgv.rows.length;
var y = 0;
for (var i = 0; i < rc; i++) {
var getInput = objgv.rows[i].cells[0].getElementsByTagName("input");
if (getInput[0].type == "checkbox") {
if (getInput[0].checked) {
y = y + 1;
}
}
}
if (y <= 0) {
alert("首先选择想要删除的记录。");
return false;
}
if (confirm("以下选择的记录将被删除。") == true)
return true;
else
return false;
}