GridView templatefield文本框和AutoCompleteExtender ASP.NET

时间:2014-01-27 07:02:20

标签: asp.net ajax vb.net gridview autocomplete

我在使用AJAX工具包时遇到了一些问题。

我有一个带有模板字段的GridView,它有一个文本框。

我为此文本框添加了一个AutoCompleteExtender。我还设置了AutoCompleteExtender的ServicePath和ServiceMethod属性。

我不会收到任何错误,但是当我在文本框中输入文字时,我不会得到任何回复。我将在下面发布代码。

由于我是AJAX的新手,我不知道在我的项目中是否还需要设置一些其他东西才能使用AJAX。

我使用ASP.NET和VB.NET进行代码隐藏。

<%@ Page Language="vb" AutoEventWireup="false" MasterPageFile="~/Plain.Master" CodeBehind="BillPatient.aspx.vb" Inherits="Test.BillPatient" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<link href="Content/themes/base/minified/jquery-ui.min.css" rel="stylesheet" type="text/css" />
<script src="Scripts/jquery-1.9.1.min.js" type="text/javascript"></script>
<script src="Scripts/jquery-ui-1.10.3.min.js" type="text/javascript"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Content" runat="server">
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSave" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="btnCancel" EventName="Click" />
</Triggers>
<ContentTemplate>
<center>
<br />
<h1>
<asp:Label ID="lblTitle" runat="server" Text="New OP Patient Bill" />
</h1>
<br />
<asp:Label ID="lblStatus" runat="server" ForeColor="Green" />
<table id="tblModify" class="table" frame="border" width="100%">
<tr>
<td>
<asp:Label ID="lblBillDetail" runat="server" Text="Bill Detail(s)" Visible="false"></asp:Label>
<asp:GridView ID="gvBillDetail" runat="server" AllowPaging="True" AutoGenerateColumns="False" CssClass="table" Width="100%">
<Columns>
<asp:BoundField DataField="Id" HeaderText="ID">
<HeaderStyle HorizontalAlign="Center" Width="50px" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:TemplateField HeaderText="Particulars">
<ItemTemplate>
<asp:TextBox ID="txtBillableItem" runat="server" Columns="30" MaxLength="30"></asp:TextBox>
<asp:AutoCompleteExtender ServiceMethod="GetCompletionList" MinimumPrefixLength="1" ID="txtBillableItem_AutoCompleteExtender" runat="server" DelimiterCharacters="" Enabled="True" ServicePath="~/BillDetail.asmx" TargetControlID="txtPatientName">
</asp:AutoCompleteExtender>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Billable Amount">
<ItemTemplate>
<asp:Label ID="lblBillableAmount" runat="server"></asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:TemplateField>
<asp:ButtonField ButtonType="Button" CommandName="Modify" HeaderText="Modify" Text="Modify">
<ControlStyle CssClass="btn btn-info btn-xs" />
<HeaderStyle HorizontalAlign="Center" Width="90px" />
<ItemStyle HorizontalAlign="Center" />
</asp:ButtonField>
</Columns>
<PagerSettings Mode="NumericFirstLast" Position="TopAndBottom" />
<PagerStyle HorizontalAlign="Right" />
</asp:GridView>
<asp:ValidationSummary ID="ValidationSummary2" runat="server" ForeColor="#993333" Style="text-align: center" Visible="True" ValidationGroup="AddBillDetail" />
<asp:Button ID="btnSave" runat="server" CssClass="btn btn-primary" Text="Save" ValidationGroup="Save" />
&nbsp;
<asp:Button ID="btnCancel" runat="server" CausesValidation="False" CssClass="btn" Text="Cancel" />
</center>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>

请原谅我没有正确格式化代码:)

我的网络服务代码是: -

Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
<System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class BillDetail
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function HelloWorld() As String
Return "Hello World"
End Function

  <System.Web.Services.WebMethodAttribute(),System.Web.Script.Services.ScriptMethodAttribute()>
Public Shared Function GetCompletionList(ByVal prefixText As String, ByVal count As Integer) As String()
' Create array of movies  
Dim movies() As String = {"Star Wars", "Star Trek", "Superman", "Memento", "Shrek", "Shrek II"}

' Return matching movies  
Return (
From m In movies
Where m.StartsWith(prefixText, StringComparison.CurrentCultureIgnoreCase)
Select m).Take(count).ToArray()
End Function

End Class

我希望以上信息足够。如果没有,请评论我会提供更多信息。 谢谢!

1 个答案:

答案 0 :(得分:0)

我自己得到了解决方案。

我刚停止使用WebService并将我的ServiceMethod放入我的代码隐藏中。

将属性ServicePath设置为您自己的页面。即如果AutoCompleteExtender在Test.aspx中且Service方法在Test.aspx.vb中,则属性将为: -

ServiceMethod="GetCompletionList" 

ServicePath="~/Test.aspx.vb"

如果ServiceMethod实际执行但如果在U.I中看不到下拉列表,则在html中的head标签中添加以下代码。

<style type="text/css" >
        .popUpDialog
    {
        z-index: 99 !important;
    }

    .autoComplete_listMain
    {
        z-index: 2147483647 !important;
        background: #ffffff;
        border: solid 2px #808080;
        color: #000000;
    }
        </style>

我不知道为什么我应该加上这个,但它肯定对我有用! :)

如果有人知道原因,请在这里自由评论....

相关问题