This is what you can do:
protected void BtnSearch_Click(object sender, ImageClickEventArgs e)
{
DataSet ds = new DataSet();
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["YourConnectionString"].ToString()))
{
using (SqlCommand command = new SqlCommand())
{
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "youProcedureName";
command.Connection = connection;
command.Parameters.AddWithValue("@ProjectCode", TbProjectCode.Text);
connection.Open();
SqlDataAdapter a = new SqlDataAdapter(command);
a.Fill(ds);
}
}
DGV.DataSource = ds;
DGV.DataBind();
}
The idea is pretty simple. On your Search(click) event you are rebinding your GridView
with a new DataSource
that you retrieved with your new SELECT
query.
VB.NET
Protected Sub BtnSearch_Click(sender As Object, e As ImageClickEventArgs)
Dim ds As New DataSet()
Using connection As New SqlConnection(ConfigurationManager.ConnectionStrings("YourConnectionString").ToString())
Using command As New SqlCommand()
command.CommandType = CommandType.StoredProcedure
command.CommandText = "youProcedureName"
command.Connection = connection
command.Parameters.AddWithValue("@ProjectCode", TbProjectCode.Text)
connection.Open()
Dim a As New SqlDataAdapter(command)
a.Fill(ds)
End Using
End Using
DGV.DataSource = ds
DGV.DataBind()
End Sub
Try this vb
code. I have used conversion tool to get this. Maybe you might require some modifications here.
Following your comment:
Add this line on your page.
public string CfgConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("CfgConnectionString").ConnectionString;
and change your first line like this:
Using connection As New SqlConnection(ConfigurationManager.ConnectionStrings("CfgConnectionString").ToString())
Also you are missing
Dim ds As New DataSet()