如何通过在gridview控件的页脚行中的javascript获取文本框值

时间:2014-09-16 05:25:16

标签: c# javascript html asp.net

我在aspx页面中使用了gridview的下面代码,请在表单标签下注意gridview。

 <Grdview:GridViewExtended ID="GridView1" runat="server"
    AutoGenerateColumns="False" CssClass="Grid"
        onpageindexchanging="GridView1_PageIndexChanging" 
        onselectedindexchanged="GridView1_SelectedIndexChanged" PageSize="6" 
        ShowFooter="True" Width="543px" 
        onselectedindexchanging="GridView1_SelectedIndexChanging" 
        AllowPaging="True" EditIndex="-1" 
    ShowHeaderWhenEmpty="True" ShowFooterWhenEmpty="True">
    <HeaderStyle CssClass ="yui-grid"/>
    <Columns>
                <asp:TemplateField HeaderText="Job_No">
                 <ItemTemplate>
                    <asp:Label ID="lbl1" runat="server" Text='<%# Eval("Job_No") %>'> </asp:Label>
                </ItemTemplate>
                <FooterTemplate>
                    <asp:TextBox ID="txtSearch" runat="server" Height="19px" Width="87px" 
                        CssClass="textEntry" ToolTip="Add New Entry"></asp:TextBox>
                        <asp:HiddenField ID="hfCustomerId" runat="server" />
                </FooterTemplate>
            </asp:TemplateField>

我的Javascript代码,我在aspx页面中使用

<script type="text/javascript">
$(document).ready(function () {

    $("#GridView1").find(".textEntry").autocomplete({
        source: function (request, response) {
            $.ajax({
                url: '<%#ResolveUrl("~/Service.asmx/GetCustomers") %>',
                dataType: "json",
                type: "POST",
                contentType: "application/json; charset=utf-8",
                success: function (data) {
                    response($.map(data.d, function (item) {
                        return {
                            label: item.split('-')[0],
                            val: item.split('-')[1]
                        }
                    }))
                },
                error: function (response) {
                    alert(response.responseText);
                },
                failure: function (response) {
                    alert(response.responseText);
                }
            });
        },
        select: function (e, i) {
            $("#<%=hfCustomerId.ClientID %>").val(i.item.val);
        },
        minLength: 1
    });
});

如何使用此Javascript代码获取文本框控件(txtSearch)?感谢

1 个答案:

答案 0 :(得分:0)

<Grdview:GridViewExtended ID="GridView1" runat="server" ClientIDMode="Static" >

ClientIDMode设为Static并执行

$(document).ready(function () {

    $("#GridView1").find(".textEntry").autocomplete({});

});