I am using TextSuggest in a custom module and have the suggest part working. I am filling a datatable and using it to get the suggest text from. I have included my code below.
Now I am at a loss for how to get the information back! I want the GUID (as a string or guid, it doesn't matter) back for the selected item to pull that school's information. I would like it to be automatic using the NodeClick method if I'm correct on how that works. That way there is no button to press, and they are limited to the choices in the textSuggest.
Is there a way to pull the OrgsID from the choice? Or do I need to re-query the db based on the .text value of the textbox and match it to the guid that way?
I am using a slightly modified version of the example given by Michael Washington at: http://www.dotnetnuke.com/Community/Blogs/tabid/825/EntryId/1067/Using-the-DNN-Text-Suggest-Control.aspx
Here is my code -- I am including some of the data access methods in case I'm not setting it up correctly to begin with (but the suggest text DOES work as expected currently):
Private Sub PopulateList(ByVal objNodes As DNNNodeCollection, ByVal strText As String)
Dim o As DNNNode
Dim dt As DataTable = GetOrgs() 'fills the datatable
'strip out troublesome chars for Select below
strText = strText.Replace("[", "").Replace("]", "").Replace("'", "''")
dt.CaseSensitive = Me.MyDNNTextSuggest.CaseSensitive
Dim drs() As DataRow = dt.Select("OrgsName like '" & strText & "%'")
Dim dr As DataRow
For Each dr In drs
If Me.MyDNNTextSuggest.MaxSuggestRows = 0 _
OrElse objNodes.Count < (Me.MyDNNTextSuggest.MaxSuggestRows + 1) Then
o = New DNNNode(CStr(dr("OrgsName")))
o.ID = CType(dr("OrgsID"), Guid).ToString()
objNodes.Add(o)
End If
Next
End Sub
Public Function GetOrgs() As DataTable
GetOrgs = FillDataTable("select OrgsID, OrgsName from vwSchoolsInfo", "vwSchoolsInfo")
End Function
Private Function FillDataTable(ByVal strSQL As String, ByVal strTableName As String) As DataTable
Dim dt As New DataTable()
Dim conProjectTrack As SqlConnection = GetConnectionObject()
Dim cmd As SqlCommand = conProjectTrack.CreateCommand
Dim da As New SqlDataAdapter(strSQL, conProjectTrack)
cmd.CommandType = CommandType.Text
cmd.CommandText = strSQL
da.SelectCommand = cmd
da.Fill(dt)
Return dt
End Function
Thanks,
Kevin