当JavaScript禁用网格asp.net中某列的所有复选框时,如何禁用“删除”按钮?
我有一个网格,其中有7列,所有复选框都在其中 残废如何禁用“删除”按钮 在下图中,如果取消SO行项目中的所有复选框 如果列被禁用,则应禁用DEL按钮 .Aspx文件当JavaScript禁用网格asp.net中某列的所有复选框时,如何禁用“删除”按钮?,javascript,c#,asp.net,gridview,checkbox,Javascript,C#,Asp.net,Gridview,Checkbox,我有一个网格,其中有7列,所有复选框都在其中 残废如何禁用“删除”按钮 在下图中,如果取消SO行项目中的所有复选框 如果列被禁用,则应禁用DEL按钮 .Aspx文件 <asp:TemplateField HeaderText="Cancel SO Line Item"> <ItemTemplate> <asp:checkbox ID="cbSOCan" runat="server" ViewStateMode="Enabled" E
<asp:TemplateField HeaderText="Cancel SO Line Item">
<ItemTemplate>
<asp:checkbox ID="cbSOCan" runat="server" ViewStateMode="Enabled" EnableViewState="true"></asp:checkbox>
</ItemTemplate>
<asp:LinkButton CssClass="btn btn-primary" ID="btnCancelItem" runat="server" CausesValidation="False"OnClientClick="return Confirmationbox();"> Cancel Item</asp:LinkButton>
<asp:HiddenField id="hdnval" value=0 runat="server"/>
protected void btnCancelItem_Click(object sender, EventArgs e)
{
foreach (GridViewRow gvrow in gvPOItems.Rows) {
CheckBox chkdelte = (CheckBox)gvrow.FindControl("cbSOCan");
HiddenField hdnval = (HiddenField)gvrow.FindControl("hdnval");
if (chkdelte.Checked) {
// gvAdditionalArea.Rows(rowIndex).Cells(0).Text()
Int32 ItemNumber = Convert.ToInt32(gvrow.Cells(0).Text());
Queries.CancelSOlineItem(ItemNumber, txtPONumber.Text);
gvrow.Cells(7).Text() = "Cancelled";
chkdelte.Checked = false;
chkdelte.Enabled = false;
hdnval.Value = 1;
}
}
protected void Page_Load(object sender, EventArgs e)
{
{if (!IsPostBack)
int rowcount = 0;
foreach (GridViewRow gvrow in gvPOItems.Rows) {
HiddenField hdnval = (HiddenField)gvrow.FindControl("hdnval");
if ((hdnval.Value == 1)) {
rowcount = rowcount + 1;
}
}
if ((gvPOItems.Rows.Count == rowcount)) {
btnCancelItem.Visible = false;
}
}
}
您可以检查RowDataBound事件中复选框的状态。如果启用了一个复选框,请将全局布尔值设置为true,然后在页脚行中设置“删除”按钮状态
bool oneCheckBoxIsEnabled = false;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//check if the row is a datarow or the footer row
if (e.Row.RowType == DataControlRowType.DataRow)
{
//check the state of the checkbox
//either by checking the source data for the value that would trigger the disable
DataRowView row = e.Row.DataItem as DataRowView;
if (Convert.ToBoolean(row["isEnabledInDB"]) == true)
{
oneCheckBoxIsEnabled = true;
}
//or the state of the checkbox with findcontrol
CheckBox cb = e.Row.FindControl("CheckBox1") as CheckBox;
if (cb.Enabled == true)
{
oneCheckBoxIsEnabled = true;
}
}
else if (e.Row.RowType == DataControlRowType.Footer)
{
//use the footer row to enable or disable the button
DeleteButton.Enabled = oneCheckBoxIsEnabled;
}
}
由Jquery提供
disableCheckbox = function () {
//checked check-boxes length
checkedCount = $('#CP_Main_gvPOItems input[type=checkbox]:checked').length;
//check-boxes length
checkboxCount = $('#CP_Main_gvPOItems input[type=checkbox]').length;
//if no check-box is selected then alert
// if (checkedCount == 0) {
// alert('No check-box is selected');
// }
//check for all disabled check-boxes
//var disableCheckBox = 0;
$('#CP_Main_gvPOItems input[type=checkbox]').each(function () {
if ($(this).is(':disabled')) {
disableCheckBox++;
}
});
//if all check-boxes are disabled then disable button
if (checkboxCount == disableCheckBox) {
$('#CP_Main_btnCancelItem').attr("disabled", "disabled"); //# is missing
}
}
还没有答案..需要帮助c#或jSok不删除它很好知道,稍等片刻,仍在等待…任何JS解决方案?删除按钮不是网格的一部分,因此此页脚操作是否有效?删除按钮位于网格外部,请更新您的答案,如果未选中任何复选框,则按钮应被禁用@VDWWDY您还需要JS解决方案吗?在你的第四条评论中,你有没有发现这个问题?