Link to home
Start Free TrialLog in
Avatar of kdeutsch
kdeutschFlag for United States of America

asked on

Use autocomplete textbox to refill gridview

WOndering if its possible to use a atuocomplete extender textbox outside of a datagriid to refresh data in grid as you type a name.  So I load the grid initially with information and then as I type in my textbox I want information in grid to fall away till i get to the person I want.  Is this possible??? and where do i start.

If its possible I will add full amount of points.
Avatar of TomasP
TomasP
Flag of United States of America image

I would start by capturing each character entered in the text box and then scan the grid for entries that match my character and remove the rest. Keep in mind you should copy the data out of the grid first so if the user backspaces you can restore information to the grid as appropriate
Also, the logic depends if you are just trimming data already in the grid or forcing a new population of data in the grid from the store based on what the user enters. If you populate the grid with the first records and the user's first letter requires records not yet read in, they you need to build a query according and pull the data from the store according per the new query.
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kdeutsch

ASKER

Hi,

Ok here is my code, what I do is fill the Gridview on a dropdown list event, then fill the gridview.
  Protected Sub ddlTasks_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlTasks.SelectedIndexChanged
        pnlGrid.Visible = True
        FillGrid()
    End Sub

    Protected Sub txtFindSoldier_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtFindSoldier.TextChanged
        FillGrid()
    End Sub

    Private Sub FillGrid()
        Dim srp As Integer = ddlSrpEvent.SelectedValue
        Dim cat As Integer = ddlTasks.SelectedValue
        Dim theCounter As Integer
        Dim SqlWhere As String

        If HFID.Value = "" Then
            SqlWhere = ""
        Else
            SqlWhere = "AND ed.intPersonnelID = '" & HFID.Value & "'"
        End If

        sql = "Select ed.intDataId, q.strTask, ed.intAnswer as Answer, ed.strData, ed.strRemarks, strDocDate, w.strFullName From tblSRPEventData as ed INNER JOIN tblSRPQuestion as q on " _
            & "q.intQuestionId = ed.intQuestionId INNER JOIN " _
            & "tblQuestionCategory as qc on qc.intCategoryId = q.intCategoryID INNER JOIN WORSDotNet.dbo.tblUser as w on w.strSSN = cast(ed.intPersonnelID as varchar) Where q.intcategoryId = " & cat & " and " _
            & "intEventId = " & srp & " and intAnswer = 1 " & SqlWhere & " Order by w.strFullname"

        myGridview.DataSource = getData(sql)
        myGridview.DataBind()

        For theCounter = 0 To myGridview.Rows.Count - 1

        Next

        lblCount.Text = theCounter & " Records"

        'Wipe the HFID for onload events
        HFID.Value = Nothing
        txtFindSoldier.Text = String.Empty
    End Sub
All,
Ok I got it to work to filter, but I the gird doe not change as it filters.
 Protected Sub ddlTasks_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlTasks.SelectedIndexChanged
        pnlGrid.Visible = True
        FillGrid()
    End Sub

    Protected Sub txtFindSoldier_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtFindSoldier.TextChanged
        myDataTable = CType(Session("mydataTable"), DataTable)
        myDataTable.DefaultView.RowFilter = "strFullname like '%" & txtFindSoldier.Text & "&'"

        FillGrid()
    End Sub

    Private Sub FillGrid()
        Dim srp As Integer = ddlSrpEvent.SelectedValue
        Dim cat As Integer = ddlTasks.SelectedValue
        Dim theCounter As Integer
        Dim SqlWhere As String

        'If HFID.Value = "" Then
        '    SqlWhere = ""
        'Else
        '    SqlWhere = "AND ed.intPersonnelID = '" & HFID.Value & "'"
        'End If

        sql = "Select ed.intDataId, q.strTask, ed.intAnswer as Answer, ed.strData, ed.strRemarks, strDocDate, w.strFullName From tblSRPEventData as ed INNER JOIN tblSRPQuestion as q on " _
            & "q.intQuestionId = ed.intQuestionId INNER JOIN " _
            & "tblQuestionCategory as qc on qc.intCategoryId = q.intCategoryID INNER JOIN WORSDotNet.dbo.tblUser as w on w.strSSN = cast(ed.intPersonnelID as varchar) Where q.intcategoryId = " & cat & " and " _
            & "intEventId = " & srp & " and intAnswer = 1 Order by w.strFullname"

        myDataTable = New DataTable
        myDataTable = getData(sql)
        Session("myDataTable") = myDataTable
        myGridview.DataSource = myDataTable
        myGridview.DataBind()

        For theCounter = 0 To myGridview.Rows.Count - 1

        Next

        lblCount.Text = theCounter & " Records"

        'Wipe the HFID for onload events
        HFID.Value = Nothing
        txtFindSoldier.Text = String.Empty
    End Sub
No response, to finish out, changed to another method.