Hi ,
check this Example it will help you
protected void Button1_Click(object sender, EventArgs e)
{
using (SqlConnection Cn = new SqlConnection(ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString))
{
using ( SqlCommand Cmd = new SqlCommand("SELECT * FROM orders WHERE orderid= @orderid", Cn))
{
Cn.Open();
Cmd.Parameters.AddWithValue("@orderid",int.Parse( TextBox1.Text));
SqlDataReader Dr = Cmd.ExecuteReader();
if (Dr.HasRows)
{
GridView1.DataSource = Dr;
GridView1.DataBind();
}
Dr.Close();
Cn.Close();
}
}
}
<div>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</div>
Best Regards
M.Mitwalli