'Calling mutliple bool routines in ASP.NET and C#

I have mutliple bool user defined routines that calls a stored procedure from SQL server. The stored procedures are working fine but the problem is I want to hide and show labels and linkbuttons in a datalist based on the bool routines but it's not coming out as such. Its only calling one bool function and displaying the results in the entire datalist as opposed to showing the specific bool routine that has been called here is a sample code of the of a single bool function.

bool GetBooksInLibrary()
{
    try
    {
        SqlConnection con = new SqlConnection(Strcon);
        if (con.State == ConnectionState.Closed)
        {
            con.Open();
        }
        SqlCommand cmd = new SqlCommand();
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "getBookInLibrary";
        cmd.Connection = con;
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        da.Fill(dt);
        //Checks if any record exists in the table with books in library and returns the entire rows with the record
        if (dt.Rows.Count >= 1)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    catch (Exception ex)
    {
        Response.Write("<script>alert('" + ex.Message + "');</script>");
        return false;
    }
}

protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        LinkButton lnkbtnAddToCart = (LinkButton)e.Item.FindControl("lnkbtnAddToCart");
        LinkButton lnkkbtnRequest = (LinkButton)e.Item.FindControl("lnkkbtnRequest");
        Label lblNote = (Label)e.Item.FindControl("lblNote");
        Label lblRequested = (Label)e.Item.FindControl("lblRequested");
        LinkButton lnkButtonRead = (LinkButton)e.Item.FindControl("lnkButtonRead");

        if (GetBooksInLibrary())
        {
            lnkbtnAddToCart.Visible = false;
            lnkkbtnRequest.Visible = false;
            lblNote.Visible = true;
            lblRequested.Visible = false;
            lnkButtonRead.Visible = false;
        }
        if (GetBooksInStores())
        {
            lnkbtnAddToCart.Visible = true;
            lnkkbtnRequest.Visible = false;
            lblNote.Visible = false;
            lblRequested.Visible = false;
            lnkButtonRead.Visible = false;
        }
        if (GetOnlineFreeBooks())
        {
            lnkbtnAddToCart.Visible = false;
            lnkkbtnRequest.Visible = false;
            lblNote.Visible = false;
            lblRequested.Visible = false;
            lnkButtonRead.Visible = true;
        }
        if (GetOnlinBooksForSale())
        {
            lnkbtnAddToCart.Visible = true;
            lnkkbtnRequest.Visible = true;
            lblNote.Visible = false;
            lblRequested.Visible = false;
            lnkButtonRead.Visible = false;
        }
    }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source