【问题标题】:How to get current row control ID's in jquery while Place Cursor TextBox in gridview asp.net?在gridview asp.net中放置光标文本框时如何在jquery中获取当前行控件ID?
【发布时间】:2018-05-08 15:09:16
【问题描述】:

在 GridView asp.net 中放置光标文本框时如何在 jQuery 中获取当前行控件 ID?

$(document).ready(function () { 
    $('.Text_Controls_Focus').focus(function () {

        $(document).ready(function () {

            $('.Text_Controls_Focus').focus(function () {
                // Need To Get ID of Current Row Of Griview  and 
                // Griview ID

                $(this).dialog('close');
            }
        },
    modal: true
});

【问题讨论】:

    标签: jquery asp.net gridview


    【解决方案1】:

    简而言之,ID 为txtFirstName 的Web 控件可以呈现为客户端ID 类似"ctl00_MainContent_txtFirstName" 的HTML 元素。 ASP.NET GridView (gdRows) 也是如此,例如:

    假设GridView里面有TextBox和Label控件。

    <ItemTemplate>
        <asp:TextBox ID="txtID" runat="server" />
        <asp:Label ID="lblID" runat="server" />
    </ItemTemplate>
    

    因此,当您运行上述代码时,HTML 中的 ID 将呈现为:

    <input name="gdRows$ctl02$txtID" type="text" id="gdRows_ctl02_txtID" />
    <span id="gdRows_ctl02_lblID"></span>
    

    现在选择 TextBox(s) 和 Label(s) 的控件,如下所示:

    // select all Labels in GridView
    $('#<%=gdRows.ClientID %>').find('span[id$="lblID"]').text('Your text.');
    
    // select a particular Label in GridView
    var $arrL = $('#<%=gdRows.ClientID %>').find('span[id$="lblID"]');
    var $lbl = $arrL[0]; // finds a Label at 0 index
    $($lbl).text('Your text...');
    
    // select all TextBoxes in GridView
    $('#<%=gdRows.ClientID %>').find('input:text[id$="txtID"]').val('Your value.');
    
    // select a particular TextBox in GridView
    var $arrL = $('#<%=gdRows.ClientID %>').find('input:text[id$="txtID"]');
    var $txt = $arrL[0]; // finds a TextBox at 0 index
    $($txt).text('Your text...');
    

    链接:http://www.jquerybyexample.net/2013/02/find-control-in-aspnet-gridview-jquery.html

    【讨论】:

    • 谢谢...我尝试了一些替代解决方案...这个解决方案可以简化我的逻辑。再次感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-25
    相关资源
    最近更新 更多