Sie sind auf Seite 1von 2

---------------COde is Start-----------------------This code for Search in Gridview and show gridview when search is

found
----------quary select * from where sid=@sid
-----take only one text box, one label and one button for search
private void search_bind()
{
using (SqlConnection con = new SqlConnection(constr))
{
//
using (SqlCommand cmd = new SqlCommand("select * from
NS2_StudentDetails where sid like'" + txtsid.Text + "%'", con))
using (SqlCommand cmd = new
SqlCommand("NS2_P_Searchstudentfor_right_or_wrong", con))
{

}
}

con.Open();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Sid", txtsid.Text);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
GridView2.DataSource = ds;
GridView2.DataBind();

protected void Button1_Click(object sender, EventArgs e)


{
try
{
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new
SqlCommand("NS2_P_Searchstudentfor_right_or_wrong", con))
//
using (SqlCommand cmd = new SqlCommand("select *
from NS2_StudentDetails where sid like'" + txtsid.Text + "%'", con))
{
con.Open();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Sid", txtsid.Text);
SqlDataReader dr;
dr = cmd.ExecuteReader();
if (dr.HasRows)

dr.Read();
search_bind();
GridView2.Visible = true;
txtsid.Text = "";
lblmsg.Text = "";

}
else
{

GridView2.Visible = false;
lblmsg.Visible = true;
lblmsg.Text = "This ----" + txtsid.Text + "---- is not
available in the Records";
}
}
}
}
catch (Exception)
{
lblmsg.Text = "This ----" + txtsid.Text + "---- is not available
in the Records";
}
}
---------This code for Search in Gridview and show gridview when search is
found
----------quary select * from where sid=@sid
-----take only one text box, one label and one button for search
---------------COde is Finished---------------

Das könnte Ihnen auch gefallen