简体   繁体   English

使用 javascript/Jquery 在 Gridview 中启用/禁用文本框的问题

[英]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.在此先感谢您的帮助:我有一个 Gridview,只有在激活复选框时才会激活文本框。 I managed to do this function in Javascript.我设法在 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> 

您可以将文本框的Enable属性设置为false

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM