如何使用Javascript从GridView隐藏选定行的CheckBox?
我在第一列中有一个带CheckBox
的GridView
,在SecondLast列上有一个Button
。 当用户单击Button
, current row
的CheckBox
必须使用Javascript
Invisible
。
<asp:CheckBox ID="chkSelect" runat="server" Height="30" class="mychk" rowid="" /> //some more templates here <asp:Button ID="BtnSource" runat="server" Text="Source" rowid="" class="showButton" OnClick='' />
使用Javascript:
function SetRowValues(id, controlid, fair, good, mint, nnew, poor, broken) { var rowid = $("#" + controlid).attr("rowid"); var chkBoxID; var chkRowid; $('.mychk').css("display", "block"); $('.mychk').each(function() { chkBoxID = this.id; alert(chkBoxID); chkRowid = $("#" + chkBoxID).attr("rowid"); alert(chkBoxID + " ROW :" + chkRowid); if (chkRowid == rowid) { $("#" + chkBoxID).css("display", "none"); } else { $("#" + chkBoxID).css("display", "block"); } }); return false; }
所有工作都很好,只是在alert
我变空了。 无法获取CheckBox
控件的ID
还试过:
$(document).ready(function() { $(function() { $(".showButton").on("click", function() { alert(".showButton clicked"); $(this).closest("tr").find(":checkbox").hide(); }); }); });
渲染CheckBox:
网格中呈现的按钮:
任何的想法?
帮助感谢!
这是我的完整解决方案:
function SetRowValues(id, controlid, fair, good, mint, nnew, poor, broken) { var rowid = $("#" + controlid).attr("rowid"); var chkBoxID; var chkRowid; $('span.mychk').each(function() { chkBoxID = $(this).attr('id'); chkRowid = $(this).attr('rowid'); if (chkRowid == rowid) { $(this).hide(); $(this).closest("td").css("border","none"); } else { $(this).show(); $(this).closest("td").css("border", "1px solid grey"); } }); return false; }
谢谢大家..! 🙂
试试以下内容:
var result = $('#<%=GridView1.ClientID %> tr td input[id*="chkSelect"][type=checkbox]:checked').map(function () { return $(this).closest('tr').find('td').eq(2).text(); }).get().join();
首先在没有回发的情况下执行此操作,将asp按钮更改为,输入type =按钮或html按钮:
//some more templates here
然后使用这样的脚本来隐藏复选框。 您不需要此复选框的ID,只需找到父行并隐藏复选框:
$(function() { $(".showButton").on("click", function() { $(this).closest("tr").find(":checkbox").hide(); }); });