gridview search functionality

Hi experts,

I have a grid view control with should be populated with what is searched for in this site. somehow can't write the search code

need assistance!!


 public void PopulateGrid()
    {
        DataSet objDs = new DataSet();

        System.Data.SqlClient.SqlConnection
        myConnection = new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["X10REPDConnectionString"].ConnectionString);
        System.Data.SqlClient.SqlDataAdapter  myCommand;
        myCommand = new System.Data.SqlClient.SqlDataAdapter("MP_CheckStaffExists", myConnection);
        myCommand.SelectCommand.CommandType = CommandType.StoredProcedure;
        myConnection.Open();
        myCommand.Fill(objDs);

        if (objDs.Tables.Count == 0)
            lblNoRecords.Visible = true;
        else
        {
            GridView1.DataSource = objDs;
            GridView1.DataBind();
        }
    }

    public void ItemDataBoundEventHandler1(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='Silver'");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFBD6'");
        }
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
       
       
    }
}
SirReadAlotAsked:
Who is Participating?
 
sasapopovicConnect With a Mentor Commented:
Hi SirReadAlot,

You should:
 - call your PopulateGrid() method from btnSearch_Click
 - modify PopulateGrid() method to accept a few parameters; those parameters would be values from text boxes where users will type-in their search criteria
 - add input parameters (search criteria) to your stored procedure (MP_CheckStaffExists)
 - add input parameters of stored procedure to myCommand  object.

Hope this will help.
0
All Courses

From novice to tech pro — start learning today.