Full Integrated Google Search Demo

This demo illustrates a rich Google search page. One that allows the user to specify a search term and then iterate through the results of the search.


Enter your search term:


Source Code
<script language="VB" runat="server">
  Const PAGE_SIZE as Integer = 5

  Sub execSearch(sender as Object, e as EventArgs)
    ViewState("startIndex") = 0
    
    DisplaySearchResults()
  End Sub
  
  
  Sub nextRecs(sender as Object, e as EventArgs)
    ViewState("startIndex") += PAGE_SIZE
    
    DisplaySearchResults()
  End Sub
  
  
  Sub prevRecs(sender as Object, e as EventArgs)
    ViewState("startIndex") -= PAGE_SIZE
    
    DisplaySearchResults()
  End Sub


  Sub DisplaySearchResults()
      searchResults.Visible = True
      
      Dim search As google.GoogleSearchService = New google.GoogleSearchService()
      Dim result as google.GoogleSearchResult
      
      result = search.doGoogleSearch("license key...", searchTerms.Text, _
                 ViewState("startIndex"), PAGE_SIZE, True, "", True, "", "", "")
      
      dlResults.DataSource = result.resultElements
      dlResults.DataBind()
      
      lblSearchResults.Text = "Viewing records " & String.Format("{0:#,###}", ViewState("startIndex")+1) & _
                " - " & String.Format("{0:#,###}", ViewState("startIndex") + PAGE_SIZE) & " of about " & _
                String.Format("{0:#,###}", result.estimatedTotalResultsCount) & ".  Search took " & _
                String.Format("{0:0.000}", result.searchTime) & " sec."
                
      btnPrev.Enabled = (ViewState("startIndex") > 0)
  End Sub  
  
</script>

<form runat="server">
Enter your search term: <asp:TextBox runat="server" id="searchTerms" OnTextChanged="execSearch" />
<asp:Button runat="server" Text="Search" OnClick="execSearch" />
<p>
<asp:panel id="searchResults" runat="server" Visible="False">
  <table width="100%" bgcolor="#eeeeee">
  <tr><td align="right">
    <asp:Label id="lblSearchResults" runat="server" />
  </td></tr>
  </table>

  <asp:DataList runat="server" id="dlResults"
        Font-Name="Verdana" Font-Size="10pt">

    <ItemTemplate>
      <span style="font-size:15pt;font-weight:bold;">
        <%# Container.DataItem.title %>
      </span><br />
      <%# Container.DataItem.snippet %><br />
      [<a href="<%# Container.DataItem.URL %>"><%# Container.DataItem.URL %></a>]
    </ItemTemplate>
  
    <SeparatorTemplate>
      <p> </p>
    </SeparatorTemplate>

  </asp:DataList>

  <table width="100%" bgcolor="#eeeeee">
  <tr><td align="right">
    <asp:LinkButton id="btnPrev" runat="server" Text="< Prev." OnClick="prevRecs" /> |
    <asp:LinkButton id="btnNext" runat="server" Text="Next. >" OnClick="nextRecs" />
  </td></tr>
  </table>
</asp:Panel>
</form>
  


[Return to the article]