//HTML
<asp:GridView ID="gvM" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox runat="server" ID="chkid" onclick="GetCheckStatus()"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox runat="server" ID="txtId"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField AccessibleHeaderText = "Name" DataField="Name" />
<asp:CheckBox runat="server" ID="chkid1" ebnable="false"></asp:CheckBox>
</Columns>
</asp:GridView>
//Javascrip
<script language="javascript" type="text/javascript">
function GetCheckStatus() {
var srcControlId = event.srcElement.id;
var targetControlId = event.srcElement.id.replace('chkid', 'txtId');
if (document.getElementById(srcControlId).checked)
document.getElementById(targetControlId).disabled = false;
else
document.getElementById(targetControlId).disabled = true;
}
</script>
//Jquery
<script src="http://code.jquery.com/jquery-1.8.2.js" type="text/javascript"></script>
$(document).ready(function () {
jScript();
});
function jScript() {
$("input[type=checkbox][id*=chkid]").click(function () {
if (this.checked) {
$(this).closest("tr").find("input[type=checkbox][id*=chkid1]").attr("checked", true);
}
else {
$(this).closest("tr").find("input[type=checkbox][id*=chkid1]").attr("checked", false);
}
});
}
//Result
No comments:
Post a Comment