I have a gridview which has the first Item Template as a checkbox (CheckBoxActiveClient), then it has some BoundFields that display data from the database, and the last column is a textbox item template (Copies) that takes input from the user. Using javascript, I want to disable the the 'Copies' textbox if the' CheckBoxActiveClient' is unchecked in that gridview row, and enable it if 'CheckBoxActiveClient' is checked. I know how to do it using autopostback, but I want to do it using javascript, because autopostback is slow response. Please check my markup and the javascript and suggest correction. Thia javascript is not working.
Thank You for your help in advance.
Thank You for your help in advance.
Code:
<head runat="server">
<link href="Styles/StyleSheet1.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
var TotalChkBx;
var Counter;
var ctrChecked;
function HeaderClick(CheckBox)
{
.....
}
function TogleCopies(CheckBox)
{
var gridViewCtlId = '<%=this.gvClients.ClientID%>';
var grid = document.getElementById(gridViewCtlId);
var gridLength = grid.rows.length;
for (var i = 1; i < gridLength - 1; i++)
{
//tb = document.getElementById('Copies');
//cb = document.getElementById('CheckBoxActiveClient');
cb = grid.rows[i].cells[0];
tb = grid.rows[i].cells[4];
if (cb.Checked = true) {
tb.Enabled = true;
}
else
{tb.Enabled = false; }
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
...
<asp:GridView ID="gvClients" runat="server" EmptyDataText="No Clients found" AutoGenerateColumns="False"
EnableViewState="false" AllowSorting="true" AllowPaging="true" PageSize="20"
OnPageIndexChanging="gridView_PageIndexChanging" CssClass="mGrid" PagerStyle-CssClass="pgr"
AlternatingRowStyle-CssClass="alt" OnRowDataBound = "gvClients_ShowClientStatus" >
<PagerSettings Position="Bottom" Mode="NumericFirstLast" FirstPageText="First"
LastPageText="Last" NextPageText="Next" PreviousPageText="Prev" />
<PagerStyle HorizontalAlign="Center" />
<Columns>
<asp:TemplateField>
<HeaderStyle HorizontalAlign="Left" VerticalAlign="Middle" />
<HeaderTemplate>
<asp:CheckBox ID="chkBxHeader" onclick="javascript:HeaderClick(this);" runat="server"
ToolTip="Click to Select/Un-Select All" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBoxActiveClient" onClick = "javascript:TogleCopies(this);" runat="server" Enabled="true" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField Visible="false">
<ItemTemplate>
<asp:Label ID="ClientName" runat="server" Text='<%# Eval("ClientName") %>' Visible="false" ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField Visible="false">
<ItemTemplate>
<asp:Label ID="Active" runat="server" Text='<%# Eval("Active") %>' Visible="false"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="Company Name" DataField="CompanyName" ItemStyle-HorizontalAlign="left" />
<asp:BoundField HeaderText="Client Name" DataField="ClientName" ItemStyle-HorizontalAlign="left" />
<asp:BoundField HeaderText="Active" DataField="Active" ItemStyle-HorizontalAlign="left" />
<asp:TemplateField>
<HeaderStyle HorizontalAlign="Left" VerticalAlign="Middle" />
<HeaderTemplate>
<asp:Label ID="HCopies" runat="server" Text = "#Copies" />
</HeaderTemplate>
<ItemStyle HorizontalAlign = "Center" />
<ItemTemplate >
<asp:Textbox ID="Copies" runat="server" Text='<%# Eval("Copies") %>' Width = "20" OnTextChanged = "Validate" AutoPostBack = "true"></asp:Textbox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemStyle HorizontalAlign = "Center" />
<ItemTemplate >
<asp:Label ID="InValid" runat="server" Text='' Width = "20"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>