title: Creating a Search Function, using stored procedure
body: <p>Supposedly I have the ProjectCode textbox:</p>
  
  <pre><code>&lt;td align="left" width="200px"&gt;
    &lt;asp:TextBox ID="TbProjectCode" runat="server" Width="194px"&gt;&lt;/asp:TextBox&gt;
  &lt;/td&gt;
  </code></pre>
  
  <p>and one imagebutton:</p>
  
  <pre><code>&lt;asp:ImageButton ID="BtnSearch" runat="server" ImageUrl="../Support/Image/MagnifierGlass.png" Width="75%" Height="75%" OnClientClick="openNewWin();return false;" /&gt;
  </code></pre>
  
  <p>and a gridview:</p>
  
  <pre><code>&lt;asp:Panel ID="PanelDGV" runat="server" Height="100%" ScrollBars="None" Width="100%"&gt;
    &lt;asp:GridView ID="DGV" runat="server" AutoGenerateColumns="False" GridLines="None" AllowPaging="true" PageSize="2" CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt"&gt;
        &lt;Columns&gt;
    &lt;asp:BoundField DataField="ProjectCode" HeaderText="Project Code" /&gt;
    &lt;asp:BoundField DataField="ProjectName" HeaderText="Project Name" /&gt;
    &lt;asp:ButtonField ButtonType="Image" ImageUrl="../Support/Image/Edit.png" ItemStyle-HorizontalAlign="Center" CommandName="CmdSearch" HeaderText="Edit"&gt;
    &lt;ItemStyle HorizontalAlign="Center"&gt;&lt;/ItemStyle&gt;
         &lt;/asp:ButtonField&gt;
            &lt;/Columns&gt;
               &lt;PagerStyle CssClass="pgr"&gt;&lt;/PagerStyle&gt;
                  &lt;AlternatingRowStyle CssClass="alt"&gt;&lt;/AlternatingRowStyle&gt;
                      &lt;/asp:GridView&gt;
                         &lt;/asp:Panel&gt;
  </code></pre>
  
  <p>and i"m using a stored procedure with query (i take the value from another database, notice the double dot in Master..[MS_Project]):</p>
  
  <pre><code>SELECT [projectCode],[projectName]
    FROM Master..[MS_Project]
    WHERE [projectCode] like '%' + @ProjectCode + '%'
    ORDER BY [projectCode] ASC
  </code></pre>
  
  <p>I want to create a search function, so the user type into the textbox what project code they want, then click the imagebutton, then the search result should be displayed in the gridview, is there anyway to do this? thank you.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I add in the .vb:</p>
  
  <pre><code>    Protected Sub BtnSearch_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles BtnSearch.Click
      Dim ds As New DataSet()
  
      Using connection As New SqlConnection(ConfigurationManager.ConnectionStrings("CfgConnectionString").ToString())
          Using command As New SqlCommand()
              command.CommandType = CommandType.StoredProcedure
              command.CommandText = "msProject_Select"
              command.Connection = connection
  
              command.Parameters.AddWithValue("@ProjectCode", TbProjectCode.Text)
  
              connection.Open()
              Dim a As New SqlDataAdapter(command)
              a.Fill(ds)
          End Using
      End Using
  
      DGV2.DataSource = ds
      DGV2.DataBind()
  End Sub
  </code></pre>
  
  <p>End Class</p>