I have a search text box I and then a button that i use for searching records.

I am able to search by IDs and status. But I want to search for date too by using the text box

Is that Possible?

ASPNET

 <div class="pull-right col-lg-11">
                 <center>
                    <asp:TextBox ID="txtSearch" runat="server" class="form-control" bordercolor="Black"></asp:TextBox>
                     </center>
                </div>
                <br />
                </div>

                        <span class="input-group-btn">
                        <asp:LinkButton ID="btnSearch" runat="server" class="btn btn" 
                        BackColor="CornflowerBlue" style="color:White" 
                    onclick="btnSearch_Click">
                        <i class="fa fa-search"></i>
                        </asp:LinkButton>
                        </span>



            </div>

Here is what i have tried at my code behind.

C# Codes: FOR BUTTON CLICKED

protected void btnSearch_Click(object sender, EventArgs e)
    {
        if (txtSearch.Text.Trim() == "")
        {
            GetPR();
        }
        else
        {
            GetPRSearch(txtSearch.Text);
        }
    }

MY GET

void GetPR()
    {
        con.Open();
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandText = "SELECT Receiving.ReceivingID, Receiving.POID, Receiving.FinalDeliveryDate, " +
            "Receiving.Status, Receiving.DateReceived, Receiving.ReceivedByID, Users.FirstName, Users.LastName, PO.CompanyName FROM Receiving " +
            "INNER JOIN Users ON Receiving.ReceivedByID=Users.UserID INNER JOIN PO ON Receiving.POID=PO.POID ORDER BY Receiving.DateReceived DESC";
        cmd.Parameters.AddWithValue("@UserID", Session["userid"].ToString());
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds, "Receiving");
        lvPurchases.DataSource = ds;
        lvPurchases.DataBind();
        con.Close();
    }

    void GetPRSearch(string keyword)
    {
        con.Open();
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandText = "SELECT Receiving.ReceivingID, Receiving.POID, Receiving.FinalDeliveryDate, " +
            "Receiving.Status, Receiving.DateReceived, Receiving.ReceivedByID, Users.FirstName, Users.LastName, PO.CompanyName FROM Receiving " +
            "INNER JOIN Users ON Receiving.ReceivedByID=Users.UserID INNER JOIN PO ON Receiving.POID=PO.POID " +
            "WHERE Receiving.ReceivingID LIKE '%" + keyword + "%' OR PO.CompanyName LIKE '%" + keyword + "%' OR Receiving.POID LIKE '%" + keyword + "%' " +
            "OR Receiving.DateReceived LIKE '%" + keyword + "%'";
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds, "Receiving");
        lvPurchases.DataSource = ds;
        lvPurchases.DataBind();
        con.Close();
    }

By using this i can search for just "April" Thankyou guys in advance! Advice are very much appreciated.

Related posts

Recent Viewed