I need to Disable a row in gridview and make the check box disable using some condition: For example:
我需要在gridview中禁用一行,并使用某些条件禁用复选框:例如:
if (row["Islicense"].toString() == "false") {
// disable the row and checkbox
}
Here the identity id is "valuemember"
这里的身份ID是“值成员”
Below is the HTML for your reference:
以下是HTML供您参考:
<table class="grid_table">
<colgroup>
<col style="width: 35px;">
<col style="width: 150px;">
<col>
</colgroup>
<tbody>
<tr valuemember="2" id="row_SelectedSiteId0" class="row_even">
<td>
<div class="bally-checkbox">
<label>
<input type="checkbox" name="bally-datagrid-select" id="actualcheckbox_SelectedSiteId">
<span></span>
</label>
</div>
</td>
<td>Employee</td>
<td class="cell-last">Recovery completed on 5/4/2015 12:43:51 PM</td>
</tr>
<tr valuemember="1" id="row_SelectedSiteId1" class="row_odd"><td><div class="bally-checkbox"><label><input type="checkbox" name="bally-datagrid-select" id="actualcheckbox_SelectedSiteId"><span></span></label></div></td><td>Asset</td><td class="cell-last">Recovery completed on 5/4/2015 12:43:51 PM</td></tr><tr valuemember="3" id="row_SelectedSiteId2" class="row_even"><td><div class="bally-checkbox"><label><input type="checkbox" name="bally-datagrid-select" id="actualcheckbox_SelectedSiteId"><span></span></label></div></td><td>Drop</td><td class="cell-last">Recovery completed on 5/4/2015 12:43:51 PM</td></tr><tr valuemember="9" id="row_SelectedSiteId3" class="row_odd"><td><div class="bally-checkbox"><label><input type="checkbox" name="bally-datagrid-select" id="actualcheckbox_SelectedSiteId"><span></span></label></div></td><td>Accounting</td><td class="cell-last">Recovery completed on 5/4/2015 12:43:51 PM</td></tr><tr valuemember="7" id="row_SelectedSiteId4" class="row_even"><td><div class="bally-checkbox"><label><input type="checkbox" name="bally-datagrid-select" id="actualcheckbox_SelectedSiteId"><span></span></label></div></td><td>Slips</td><td class="cell-last">Recovery completed on 5/4/2015 12:43:51 PM</td></tr><tr valuemember="5" id="row_SelectedSiteId5" class="row_odd"><td><div class="bally-checkbox"><label><input type="checkbox" name="bally-datagrid-select" id="actualcheckbox_SelectedSiteId"><span></span></label></div></td><td>Tickets</td><td class="cell-last">Recovery completed on 5/4/2015 12:43:51 PM</td></tr>
</tbody>
</table>
3 个解决方案
#1
Iterate over the table row and detect the desired attribute, compare with your criteria and disable, or not the respective row.
迭代表行并检测所需属性,与您的条件进行比较并禁用,或者不是相应的行。
In this case, you will disable every row that has a valuemember attribute equal to yourCriteria
在这种情况下,您将禁用valuemember属性等于yourCriteria的每一行
jQuery
$('.grid_table tr').each(function() {
var that = $(this);
if (that.attr('valuemember') == 'yourCriteria') {
that.find('input[type=checkbox]').prop('disabled', true);
that.addClass('disabledRow');
}
});
CSS
.disabledRow {
opacity: 0.3
}
DEMO (disable row with valuemember == 1)
DEMO(禁用具有值成员的行== 1)
$('.grid_table tr').each(function() {
var that = $(this);
if (that.attr('valuemember') == '1') {
that.find('input[type=checkbox]').prop('disabled', true);
that.addClass('disabledRow');
}
});
.disabledRow {
opacity: 0.3
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table class="grid_table">
<colgroup>
<col style="width: 35px;">
<col style="width: 150px;">
<col>
</colgroup>
<tbody>
<tr valuemember="2" id="row_SelectedSiteId0" class="row_even">
<td>
<div class="bally-checkbox">
<label>
<input type="checkbox" name="bally-datagrid-select" id="actualcheckbox_SelectedSiteId">
<span></span>
</label>
</div>
</td>
<td>Employee</td>
<td class="cell-last">Recovery completed on 5/4/2015 12:43:51 PM</td>
</tr>
<tr valuemember="1" id="row_SelectedSiteId1" class="row_odd"><td><div class="bally-checkbox"><label><input type="checkbox" name="bally-datagrid-select" id="actualcheckbox_SelectedSiteId"><span></span></label></div></td><td>Asset</td><td class="cell-last">Recovery completed on 5/4/2015 12:43:51 PM</td></tr><tr valuemember="3" id="row_SelectedSiteId2" class="row_even"><td><div class="bally-checkbox"><label><input type="checkbox" name="bally-datagrid-select" id="actualcheckbox_SelectedSiteId"><span></span></label></div></td><td>Drop</td><td class="cell-last">Recovery completed on 5/4/2015 12:43:51 PM</td></tr><tr valuemember="9" id="row_SelectedSiteId3" class="row_odd"><td><div class="bally-checkbox"><label><input type="checkbox" name="bally-datagrid-select" id="actualcheckbox_SelectedSiteId"><span></span></label></div></td><td>Accounting</td><td class="cell-last">Recovery completed on 5/4/2015 12:43:51 PM</td></tr><tr valuemember="7" id="row_SelectedSiteId4" class="row_even"><td><div class="bally-checkbox"><label><input type="checkbox" name="bally-datagrid-select" id="actualcheckbox_SelectedSiteId"><span></span></label></div></td><td>Slips</td><td class="cell-last">Recovery completed on 5/4/2015 12:43:51 PM</td></tr><tr valuemember="5" id="row_SelectedSiteId5" class="row_odd"><td><div class="bally-checkbox"><label><input type="checkbox" name="bally-datagrid-select" id="actualcheckbox_SelectedSiteId"><span></span></label></div></td><td>Tickets</td><td class="cell-last">Recovery completed on 5/4/2015 12:43:51 PM</td></tr>
</tbody>
</table>
#2
How about this:
这个怎么样:
if($('tr[valuemember="0"]').length){}
#3
$('.grid_table tr').each(function() {
var attr = $(this).attr('valuemember');
if (typeof attr !== typeof undefined && attr !== false) {
// has valuemember attribute
}
});
#1
Iterate over the table row and detect the desired attribute, compare with your criteria and disable, or not the respective row.
迭代表行并检测所需属性,与您的条件进行比较并禁用,或者不是相应的行。
In this case, you will disable every row that has a valuemember attribute equal to yourCriteria
在这种情况下,您将禁用valuemember属性等于yourCriteria的每一行
jQuery
$('.grid_table tr').each(function() {
var that = $(this);
if (that.attr('valuemember') == 'yourCriteria') {
that.find('input[type=checkbox]').prop('disabled', true);
that.addClass('disabledRow');
}
});
CSS
.disabledRow {
opacity: 0.3
}
DEMO (disable row with valuemember == 1)
DEMO(禁用具有值成员的行== 1)
$('.grid_table tr').each(function() {
var that = $(this);
if (that.attr('valuemember') == '1') {
that.find('input[type=checkbox]').prop('disabled', true);
that.addClass('disabledRow');
}
});
.disabledRow {
opacity: 0.3
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table class="grid_table">
<colgroup>
<col style="width: 35px;">
<col style="width: 150px;">
<col>
</colgroup>
<tbody>
<tr valuemember="2" id="row_SelectedSiteId0" class="row_even">
<td>
<div class="bally-checkbox">
<label>
<input type="checkbox" name="bally-datagrid-select" id="actualcheckbox_SelectedSiteId">
<span></span>
</label>
</div>
</td>
<td>Employee</td>
<td class="cell-last">Recovery completed on 5/4/2015 12:43:51 PM</td>
</tr>
<tr valuemember="1" id="row_SelectedSiteId1" class="row_odd"><td><div class="bally-checkbox"><label><input type="checkbox" name="bally-datagrid-select" id="actualcheckbox_SelectedSiteId"><span></span></label></div></td><td>Asset</td><td class="cell-last">Recovery completed on 5/4/2015 12:43:51 PM</td></tr><tr valuemember="3" id="row_SelectedSiteId2" class="row_even"><td><div class="bally-checkbox"><label><input type="checkbox" name="bally-datagrid-select" id="actualcheckbox_SelectedSiteId"><span></span></label></div></td><td>Drop</td><td class="cell-last">Recovery completed on 5/4/2015 12:43:51 PM</td></tr><tr valuemember="9" id="row_SelectedSiteId3" class="row_odd"><td><div class="bally-checkbox"><label><input type="checkbox" name="bally-datagrid-select" id="actualcheckbox_SelectedSiteId"><span></span></label></div></td><td>Accounting</td><td class="cell-last">Recovery completed on 5/4/2015 12:43:51 PM</td></tr><tr valuemember="7" id="row_SelectedSiteId4" class="row_even"><td><div class="bally-checkbox"><label><input type="checkbox" name="bally-datagrid-select" id="actualcheckbox_SelectedSiteId"><span></span></label></div></td><td>Slips</td><td class="cell-last">Recovery completed on 5/4/2015 12:43:51 PM</td></tr><tr valuemember="5" id="row_SelectedSiteId5" class="row_odd"><td><div class="bally-checkbox"><label><input type="checkbox" name="bally-datagrid-select" id="actualcheckbox_SelectedSiteId"><span></span></label></div></td><td>Tickets</td><td class="cell-last">Recovery completed on 5/4/2015 12:43:51 PM</td></tr>
</tbody>
</table>
#2
How about this:
这个怎么样:
if($('tr[valuemember="0"]').length){}
#3
$('.grid_table tr').each(function() {
var attr = $(this).attr('valuemember');
if (typeof attr !== typeof undefined && attr !== false) {
// has valuemember attribute
}
});