AutoCompleteExtender with a datagrid

Last post 08-01-2009 12:06 AM by kgooding. 1 replies.

Sort Posts:

  • AutoCompleteExtender with a datagrid

    07-31-2009, 6:35 PM
    • Member
      2 point Member
    • dhuss
    • Member since 03-24-2009, 2:33 PM
    • Posts 18

     I have a very simple web page that has a user control that contains the autocompleteextender. All properties for this control are set in the page_load event. This works fine. I can get the data I want to use in the autocomplete. Once a row is selected, I get the item text (works okay). I then use this to query a SQL database and return a dataset (works okay). I can see all of my returned data and can bind it to my datagrid without any problems. Only problem is the datagrid won't display on the page. If I hard code and bypass the ajax control, the datagrid will display. All of the vb.net code works great.

    This is the page_load code:

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
            '\\ rem this out and use code below, datagrid displays
            With Me.objAjaxAuto
                .AjaxCompletionInterval = 2
                .AjaxCompletionSetCount = 10
                .AjaxClearAfterSelect = False
                .AjaxMinPrefixLength = 2
                .AjaxServiceMethod = "GetSubscriberList"
                .AjaxServicePath = "~/WebMethods/AjaxMethods.asmx"
                .SubmitterID = "DALH"
                .AjaxWaterMarktext = "Enter a Last Name"
                .AjaxOnClickSubmit = True
                .AjaxHighlightResults = False
                .AjaxProgressAnimate = False
            End With
            '\\
    
            '\\un-rem this and datagrid displays
    
            'dsSubsList = RtnSubscriberAutoFill("HUSB", "", "DALH", "Subscriber")
    
            'dgListItems.Visible = True
    
            'dgListItems.CurrentPageIndex = 0
    
            'dgListItems.DataSource = dsSubsList.Tables(0)
    
            'dgListItems.DataBind()
    
            '\\
    
        End Sub

    This is the web page html code:

    <body>
        <form id="form1" runat="server" method="post" leftmargin="0" topmargin="0" rightmargin="0"
        ms_positioning="GridLayout">
        <act1:ToolkitScriptManager runat="server" ID="ScriptManager1" />
        <div style="padding: 10px;">
            <uc1:AjaxAutoDD runat="server" ID="objAjaxAuto"></uc1:AjaxAutoDD>
            <asp:UpdatePanel ID="resultPanel" runat="server" UpdateMode="Conditional">
                <ContentTemplate>
                    <asp:Label runat="server" ID="ValueSelectedLbl" /><br />
                    <asp:Label runat="server" ID="TextSelectedLbl" Style="background-color: #c2c2c2;" />
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="objAjaxAuto" EventName="ValueSelected" />
                </Triggers>
            </asp:UpdatePanel>
            <table id="tblListItems" cellspacing="0" cellpadding="0" width="100%" border="2px">
                <tr>
                    <td>
                        <asp:DataGrid ID="dgListItems" runat="server" CssClass="labelText" Width="100%" AutoGenerateColumns="False">
                            <AlternatingItemStyle CssClass="gridAlternateItem"></AlternatingItemStyle>
                            <ItemStyle CssClass="gridlabelText"></ItemStyle>
                            <HeaderStyle CssClass="gridHeader"></HeaderStyle>
                            <Columns>
                                ...
                            </Columns>
                        </asp:DataGrid>
                    </td>
                </tr>
            </table>
        </div>
        <input id="txtSearch" type="hidden" name="hidMode" runat="server" />
        </form>
    </body>

    This is the code for the AsnycPostBackTrigger eventname="ValueSelected":

        Protected Sub objAjaxAuto_ValueSelected(ByVal sender As Object, ByVal e As System.EventArgs) Handles objAjaxAuto.ValueSelected
    
            Try
    
                Dim sSearch As String
    
                sSearch= objAjaxAuto.AjaxSelectedItemText.ToString
                dsSubsList = RtnSubscriberAutoFill(sSearch, "", "DALH", "Subscriber") '<-- data is returned okay
    
                dgListItems.Visible = True
    
                dgListItems.CurrentPageIndex = 0
    
                dgListItems.DataSource = dsSubsList.Tables(0)
    
                dgListItems.DataBind()  '<-- binding occurs okay
    
                ValueSelectedLbl.Text = objAjaxAuto.AjaxSelectedItemID.ToString()
    
                TextSelectedLbl.Text = objAjaxAuto.AjaxSelectedItemText.ToString()
    
            Catch ex As Exception
    
            End Try
    
        End Sub
    


    Can anyone explain why the datagrid refuses to display??

  • Re: AutoCompleteExtender with a datagrid

    08-01-2009, 12:06 AM
    Answer
    • Participant
      1,070 point Participant
    • kgooding
    • Member since 03-05-2007, 2:41 PM
    • Laguna Niguel
    • Posts 185

    Stick it inside the update panel. Within the ContentTemplate.


    You;re currently doing a partial postback and not "reloading" the whole page, just the part what's inside of the update panel :)

    http://www.suckmycode.net

    If I answered your question please "Mark as Answer"
Page 1 of 1 (2 items)