Hi,
I am using the AjaxControlToolkit AutoCompleteExtender inside an ASP.NET AJAX RadGrid. It works fine with the following code:
<script type="text/javascript" language="javascript">
function GetDogID(source, eventArgs) {
var DogIDTxt = document.getElementById('<%=DogIDTxt.ClientID%>');
DogIDTxt.value = eventArgs.get_value();
}
</script>
<telerik:GridTemplateColumn DataField="trialCode" HeaderText="trialCode"
SortExpression="trialCode" UniqueName="trialCode">
<EditItemTemplate>
<asp:TextBox ID="trialCodeTextBox" runat="server" autocomplete="off" onKeyPress="KeyPress()"></asp:TextBox>
<cc1:AutoCompleteExtender ID="trialCodeTextBox_AutoCompleteExtender" runat="server"
DelimiterCharacters="" Enabled="True"
ServicePath="/assets/webservice/DogList.asmx" TargetControlID="trialCodeTextBox"
ServiceMethod="GetCompletionList" MinimumPrefixLength="2"
CompletionSetCount="20" CompletionInterval="0" OnClientItemSelected="GetDogID"
>
</cc1:AutoCompleteExtender>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="trialCodeLabel" runat="server" Text='<%# Eval("trialCode") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
I use a web service to pull a list of values from a database and all is well.
However...
I am using the OnClientItemSelected method (relatively new to AutoCompleteExtender so that I am able to pull back a value pair from the web service: 1.) the text value (which I'm displaying as 'autocomplete' in the RadGrid textbox while in edit mode and 2.) a primary key ID value of the item that i'm placing on a label control somewhere else on the page for now while i'm trying to figure out how to get it inside the RadGrid for use in updating.
What I need to do is be able to submit the update (or add a new record) from the RadGrid and use the primary key value on the page and NOT the text value pulled from the autocomplete.
The user needs to be able to select from a 'friendly' text-based list of about 3,000 items (hence, the need for autocomplete). Then, once selected, the primary key (from the value pair that was returned from the web service) needs to be the value that the RadGrid inserts when making the update---not the text value as there could be duplicates.
Is this possible?
Chris
Here's the web service i'm using:
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
<System.Web.Script.Services.ScriptService()> _
Public Class DogList
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function GetCompletionList(ByVal prefixText As String, ByVal count As Integer) As String()
Dim connString As String = ConfigurationManager.AppSettings("DataConnect2")
Dim conn As New SqlConnection(connString)
Dim mycommand As New SqlCommand
Dim rs As SqlDataReader
Dim items As New List(Of String)
'we add the prefixText into our SQL query to retrieve the options
'for our autocomplete
Dim strsql As String = "SELECT registrationNumber, dogName + ' - #' + registrationNumber As 'TheDog' FROM Dogs WHERE dogName LIKE '" & Replace(prefixText, "'", "''") & "%' ORDER BY dogName ASC"
mycommand.Connection = conn
mycommand.CommandText = strsql
Try
conn.Open()
rs = mycommand.ExecuteReader
If rs.HasRows Then
'we loop through the results adding each result to our list of
'items
Do While rs.Read
Dim thevalues As String = AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(rs("TheDog").ToString(), rs("registrationNumber").ToString())
items.Add(thevalues)
Loop
End If
Catch ex As Exception
items.Add(ex.ToString)
' this will show the exception in the autocomplete list if
' there are any errors
Finally
mycommand.Dispose()
conn.Close()
conn.Dispose()
End Try
Return items.ToArray ' we return our list of items as an array
End Function
I am using the AjaxControlToolkit AutoCompleteExtender inside an ASP.NET AJAX RadGrid. It works fine with the following code:
<script type="text/javascript" language="javascript">
function GetDogID(source, eventArgs) {
var DogIDTxt = document.getElementById('<%=DogIDTxt.ClientID%>');
DogIDTxt.value = eventArgs.get_value();
}
</script>
<telerik:GridTemplateColumn DataField="trialCode" HeaderText="trialCode"
SortExpression="trialCode" UniqueName="trialCode">
<EditItemTemplate>
<asp:TextBox ID="trialCodeTextBox" runat="server" autocomplete="off" onKeyPress="KeyPress()"></asp:TextBox>
<cc1:AutoCompleteExtender ID="trialCodeTextBox_AutoCompleteExtender" runat="server"
DelimiterCharacters="" Enabled="True"
ServicePath="/assets/webservice/DogList.asmx" TargetControlID="trialCodeTextBox"
ServiceMethod="GetCompletionList" MinimumPrefixLength="2"
CompletionSetCount="20" CompletionInterval="0" OnClientItemSelected="GetDogID"
>
</cc1:AutoCompleteExtender>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="trialCodeLabel" runat="server" Text='<%# Eval("trialCode") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
I use a web service to pull a list of values from a database and all is well.
However...
I am using the OnClientItemSelected method (relatively new to AutoCompleteExtender so that I am able to pull back a value pair from the web service: 1.) the text value (which I'm displaying as 'autocomplete' in the RadGrid textbox while in edit mode and 2.) a primary key ID value of the item that i'm placing on a label control somewhere else on the page for now while i'm trying to figure out how to get it inside the RadGrid for use in updating.
What I need to do is be able to submit the update (or add a new record) from the RadGrid and use the primary key value on the page and NOT the text value pulled from the autocomplete.
The user needs to be able to select from a 'friendly' text-based list of about 3,000 items (hence, the need for autocomplete). Then, once selected, the primary key (from the value pair that was returned from the web service) needs to be the value that the RadGrid inserts when making the update---not the text value as there could be duplicates.
Is this possible?
Chris
Here's the web service i'm using:
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
<System.Web.Script.Services.ScriptService()> _
Public Class DogList
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function GetCompletionList(ByVal prefixText As String, ByVal count As Integer) As String()
Dim connString As String = ConfigurationManager.AppSettings("DataConnect2")
Dim conn As New SqlConnection(connString)
Dim mycommand As New SqlCommand
Dim rs As SqlDataReader
Dim items As New List(Of String)
'we add the prefixText into our SQL query to retrieve the options
'for our autocomplete
Dim strsql As String = "SELECT registrationNumber, dogName + ' - #' + registrationNumber As 'TheDog' FROM Dogs WHERE dogName LIKE '" & Replace(prefixText, "'", "''") & "%' ORDER BY dogName ASC"
mycommand.Connection = conn
mycommand.CommandText = strsql
Try
conn.Open()
rs = mycommand.ExecuteReader
If rs.HasRows Then
'we loop through the results adding each result to our list of
'items
Do While rs.Read
Dim thevalues As String = AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(rs("TheDog").ToString(), rs("registrationNumber").ToString())
items.Add(thevalues)
Loop
End If
Catch ex As Exception
items.Add(ex.ToString)
' this will show the exception in the autocomplete list if
' there are any errors
Finally
mycommand.Dispose()
conn.Close()
conn.Dispose()
End Try
Return items.ToArray ' we return our list of items as an array
End Function