简体   繁体   English

使用Java禁用gridview中的文本框

[英]Disabling textbox in gridview using Javascript

Part of my gridview looks like this: 我的一部分GridView看起来像这样:

                    <asp:TemplateField HeaderText="Mortality Rate" SortExpression="Other2">
                <EditItemTemplate >
                    <asp:TextBox ID="txtAppLimit" Text='<%#Bind("Other2")%>' runat="server" width="60px" maxlength="14">
                    </asp:TextBox>
                     <asp:RangeValidator ID="RVAppLimit" Type="Currency" runat="server" ControlToValidate="txtAppLimit"  
                            Display="Dynamic" ErrorMessage="" Font-Size="8pt" 
                            CssClass="msgerror" MinimumValue="0" MaximumValue="200" OnPreRender="GridView1_PreRender" ValidationGroup="group1"> 
                    </asp:RangeValidator>  
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="lblAppLimit" Runat="server" Text='<%# Bind("Other2") %>' >
                    </asp:Label>
                </ItemTemplate>
                    <ItemStyle HorizontalAlign="Right" Width="10%" />
                </asp:TemplateField>

I'm trying to get the asp TextBox ID and asp Label ID in this way when I click on a asp LinkButton: 当我单击asp LinkBut​​ton时,我试图以此方式获取asp TextBox ID和asp Label ID:

        var $arrL = $('#<%=GridView1.ClientID %>').find('span[id$="lblAppLimit"]');
        var $lbl = $arrL[0];
        ($lbl).disabled = true;
        alert (($lbl).disabled);

        var $arrT = $('#<%=GridView1.ClientID %>').find('input:text[id$="txtAppLimit"]').val();
        var $txt = $arrT[0];
        alert (($txt).innerHTML);

I have no problem disabling lblAppLimit, however I'm not able to get the textbox ID to disable it. 禁用lblAppLimit没问题,但是我无法获取文本框ID来禁用它。 What is wrong with my code above? 我上面的代码有什么问题?

Just to add on another note, when I click on view source on my browser, I'm able to see lblAppLimit, but not txtAppLimit. 只是要补充一点,当我在浏览器上单击查看源时,我可以看到lblAppLimit,但看不到txtAppLimit。

Make you txtAppLimit as STATIC like this : 使您将txtAppLimit设为STATIC,例如:

1 <asp:TextBox ID="txtAppLimit" Text='<%#Bind("Other2")%>' width="60px" maxlength="14" ClientIDMode="Static" runat="server"></asp:TextBox> 1 <asp:TextBox ID="txtAppLimit" Text='<%#Bind("Other2")%>' width="60px" maxlength="14" ClientIDMode="Static" runat="server"></asp:TextBox>

and change the jquery to : 并将jquery更改为:

1 $(this).find('input:text[id="txtAppLimit"]').val(); 1 $(this).find('input:text[id="txtAppLimit"]').val();

Update: You can also try with adding class to every TextBoxes like txtclass1,txtclass2 更新:您还可以尝试将类添加到每个文本框,例如txtclass1,txtclass2

alert($(this).parent("td").parent("tr").find(".txtclass1").val()); 
alert($(this).parent("td").parent("tr").find(".txtclass2").val());

txtAppLimit is in EditItemTemplate so it will only work if the grid is in edit mode txtAppLimit位于EditItemTemplate因此只有在网格处于编辑模式时它才有效

So in edit mode try this script 所以在编辑模式下尝试这个脚本

var $arrT = $('#<%=GridView1.ClientID %>').find('input:text[id*="txtAppLimit"]').val();
        var $txt = $arrT[0];
        alert (($txt).innerHTML);

i don't know why you are using $arrT[0] but this will surely work in edit mode 我不知道您为什么使用$arrT[0]但是这肯定会在编辑模式下工作

$('#<%=GridView1.ClientID %>').find('input:text[id*="txtAppLimit"]').val()

Hope this will help you. 希望这会帮助你。

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

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