Search code examples
javascriptc#jqueryasp.netascx

Problem with Enable/disable text box in Gridview, with javascript/Jquery


thanks in advance for your help: I have a Gridview, the TextBox is activated only when the checkbox is activated. I managed to do this function in Javascript. But the problem is that the textbox is enabled by default (see image). It is deactivated after pressing the checkbox twice. I would like to solve this problem could you please help me. Thank you so much ! Look the image here !!

Here my code :

<div>
       <asp:GridView ID="gvModifOuvrageNonControles" runat="server" AutoGenerateColumns="false" SkinID="MarionGridView">
            <Columns>
                <asp:BoundField DataField="MirePrincipal" HeaderText="OUVRAGE PRINCIPAL" />
                <asp:BoundField DataField="LibelleMireSecondaire" HeaderText="OUVRAGE SECONDAIRE" />
                <asp:TemplateField HeaderText="NON CONTROLE">
                    <ItemTemplate>
                        <asp:CheckBox ID="cbInspection" OnClick="grisé(this);" runat="server" />
                    </ItemTemplate>
                </asp:TemplateField> 
                <asp:BoundField DataField="Libellel" HeaderText="LIBELLE DES MS,VI,PI,SU,CP,PL,PF" />
                <asp:TemplateField HeaderText="RAISON">
                    <ItemTemplate>
                        <asp:TextBox ID="txtCause" On runat="server"></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    </div>
    <script type="text/javascript">

        function grisé(obj) {
            var rowData = obj.parentNode.parentNode;
            if (rowData.cells[2].firstElementChild.checked == false) {
                rowData.cells[4].firstElementChild.disabled = true;
            }
            else {
                rowData.cells[4].firstElementChild.disabled = false;

            }}

    </script> 

Solution

  • You can set the Enable property of the textbox to false

    <asp:TextBox ID="txtCause" runat="server" Enabled="false"></asp:TextBox>