0
我有一個Grid view
其中他們是複選框在第一列。現在,我想隱藏所選行的CheckBox
。 我試着用下面的方法隱藏CheckBox
但它不會工作。如何在類中查找CheckBox並使用JQuery隱藏CheckBox?
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AllowPaging="true"
PageSize="100" AllowSorting="true" DataSourceID="sqlUsers" DataKeyNames="ttppcid"
Width="100%" OnRowCommand="GridView1_RowCommand" EmptyDataText="No Data Found"
OnPageIndexChanging="GridView1_PageIndexChanging" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:TemplateField ItemStyle-Width="30px" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" Visible="true">
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" Height="30" class="mychk" rowid="<%# Container.DataItemIndex+1 %>" />
</ItemTemplate>
</asp:TemplateField>
//some more templates here
<asp:TemplateField HeaderText="" ItemStyle-Width="70px" ItemStyle-HorizontalAlign="Center"
HeaderStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Button ID="BtnSource" runat="server" Text="Source" rowid="<%# Container.DataItemIndex+1 %>"
class="showButton" OnClick='<%# "return SetRowValues("+Eval("ttppcid")+",this.id,"+Eval("Fair")+","+Eval("Good")+","+Eval("Mint")+","+Eval("Poor")+","+Eval("Fair")+")"%>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
的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;
}
AlsoTRied有了:
<script type="text/javascript">
$(document).ready(function() {
$(function() {
$(".showButton").on("click", function() {
alert(".showButton clicked");
$(this).closest("tr").find(":checkbox").hide();
});
});
});
</script>
呈現標記:
渲染複選框:
<td align="center" style="width: 30px; display: block;">
<span class="mychk" rowid="1" style="display: block; height: 30px;"><input id="ctl00_ContentPlaceHolder1_GridView1_ctl02_chkSelect" type="checkbox" name="ctl00$ContentPlaceHolder1$GridView1$ctl02$chkSelect"></span>
</td>
**Rendered Button in Grid:**
<td align="center" style="width: 70px; display: block;">
<input type="submit" name="ctl00$ContentPlaceHolder1$GridView1$ctl03$BtnSource" value="Source" onclick="return SetRowValues(6,this.id,222.0000,222.0000,222.0000,222.0000,222.0000);WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ContentPlaceHolder1$GridView1$ctl03$BtnSource", "", true, "", "", false, false))" id="ctl00_ContentPlaceHolder1_GridView1_ctl03_BtnSource" class="showButton" rowid="1" style="">
</td>
注意:我想隱藏Button的'rowid'與CheckBox的'rowid'匹配的CheckBox。
你已經問過這個問題,它已經回答了,請不要轉貼同樣的問題。使用原始問題並說明爲什麼那裏的解決方案不適合你。 http://stackoverflow.com/questions/21458044/how-to-hide-checkbox-of-selected-row-from-gridview-using-javascript – Esko
但它仍然不會工作.. –
像http://jsfiddle.net/arunpjohny/NpC5q/3 /? –