Thursday, August 22, 2019

Show red Heart Icon on Hover of LinkButton and display grey on mouse out

aspx

<script type="text/javascript">

 function setclass1() {
        //  alert("helo5");
        try {
            var favid = "#<%=FavId%>";
            /// alert(favid);

            $("#<%=FavId%>").removeAttr("style");
            $("#<%=FavId%>").attr("class", "fa-heart1");

            $("#<%=FavId1%>").removeAttr("style");
            $("#<%=FavId1%>").attr("class", "fa-heart1");

            $("#<%=FavId1%>").removeAttr("style");
            $("#<%=FavId1%>").attr("class", "fa-heart1");

            $("#<%=FavId2%>").removeAttr("style");
            $("#<%=FavId2%>").attr("class", "fa-heart1");

            var FavIdList = "<%=FavIdList%>";
            FavIdList = FavIdList.split(':');
            //  alert(FavIdList);
            //  $.each(FavIdList, function (i) {
            //     alert(FavIdList[i]);
            // });
            for (i = 0; i < FavIdList.length; i++) {

                $(FavIdList[i]).removeAttr("style");
                $(FavIdList[i]).attr("class", "fa-heart1");
            }



            var FavIdList1 = "<%=FavIdList1%>";
            FavIdList1 = FavIdList1.split(':');
            //  alert(FavIdList);
            //  $.each(FavIdList, function (i) {
            //     alert(FavIdList[i]);
            // });
            for (j = 0; j < FavIdList1.length; j++) {

                $(FavIdList1[j]).removeAttr("style");
                $(FavIdList1[j]).attr("class", "fa-heart1");
            }

            var FavIdList2 = "<%=FavIdList2%>";
            FavIdList2 = FavIdList2.split(':');
            //  alert(FavIdList);
            //  $.each(FavIdList, function (i) {
            //     alert(FavIdList[i]);
            // });
            for (k = 0; k < FavIdList2.length; k++) {

                $(FavIdList2[k]).removeAttr("style");
                $(FavIdList2[k]).attr("class", "fa-heart1");
            }

        } catch (err) {
            //  alert("error");
        }


    }

function setclass() {
        // alert("HI");
        $('#ctl00_CustomerMainContent_e2wItemLayout1_lnkbtn1_addtolist').removeAttr("style");
        $('#ctl00_CustomerMainContent_e2wItemLayout1_lnkbtn1_addtolist').attr("class", "fa-heart1-o");


        if ("<%=ItemcountRepeater%>" > 0) {
            var link = "<%=ItemcountRepeater%>";
            //  alert(link);

            $("a[id*='lnkbtn1_addtolist']").removeAttr("style");
            $("a[id*='lnkbtn1_addtolist']").attr("class", "fa-heart1-o");

            $("a[id*='lnkbtn1_addtolist1']").removeAttr("style");
            $("a[id*='lnkbtn1_addtolist1']").attr("class", "fa-heart1-o");
            $("a[id*='lnkbtn1_addtolist2']").removeAttr("style");
            $("a[id*='lnkbtn1_addtolist2']").attr("class", "fa-heart1-o");
        }

 $(document).ready(function () {
               setclass();
   setclass1();
 });

</script>
<style>
.fa-heart1 {
    color: red !important;
    background-image: url(images/icon-heart-active.png);
    float: left;
    background-repeat: no-repeat;
    display: inline-block;
    width: 50px;
    height: 30px;
}

.fa-heart1:hover {
    color: red !important;
    background-image: url(images/icon-heart-active.png);
    float: left;
    background-repeat: no-repeat;
    display: inline-block;
    width: 50px;
    height: 30px;
}

.fa-heart1-o:hover {
    color: red !important;
    background-image: url(images/icon-heart-active.png);
    float: left;
    background-repeat: no-repeat;
    display: inline-block;
    width: 50px;
    height: 30px;
}

.fa-heart1-o {
    color: gray !important;
    background-image: url(images/icon-heart.png);
    float: left;
    background-repeat: no-repeat;
    display: inline-block;
    width: 50px;
    height: 30px;
}
</style>

 <asp:LinkButton ID="lnkbtn1_addtolist1"  Visible="true" runat="server" OnClientClick="return setclass1();"  OnClick="LBAddToList1_Click"></asp:LinkButton>

aspx.cs page

   public string FavId = "";
        public string FavId1 = "";
        public string FavId2 = "";
        public string FavIdList = "";
        public string FavIdList1 = "";
        public string FavIdList2 = "";

Sample code

  protected void Repeater2_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            // FavIdList = "";
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                try
                {
                    string itemID = ((DataRowView)e.Item.DataItem).Row["ItemId"].ToString().Trim();
                    string parentID = ((DataRowView)e.Item.DataItem).Row["LongItemNumber"].ToString().Trim();

                    // RepeaterItem item = (sender as LinkButton).NamingContainer as RepeaterItem;
                    // FavIdList = item.ClientID + "_lnkbtn1_addtolist1";

                    string ItemIdFav = "";

                    string sqlQuery2 = string.Format(" select ItemId from e2wListItem where ListId in (select top 1 ListId from e2wList where ListName='My Favourite') and CreatedBy='" + signOn.User.UserId.Trim() + "' order by SeqNo");
                    DataSet dsLists2 = new DataSet();
                    if (DBtools.GetDataset(sqlQuery2, "e2wList2", ref dsLists2))
                    {
                        foreach (DataRow row in dsLists2.Tables[0].Rows)
                        {
                            ItemIdFav = row["ItemId"].ToString();
                            if (ItemIdFav.Trim().Equals(itemID))
                            {
                                if (string.IsNullOrEmpty(FavIdList) || string.IsNullOrEmpty(FavIdList1))
                                {
                                    FavIdList = "#" + e.Item.ClientID + "_lnkbtn1_addtolist1";
                                    FavIdList1 = "#" + e.Item.ClientID + "_lnkbtn1_addtolist2";
                                }
                                else
                                {
                                    FavIdList += ":" + "#" + e.Item.ClientID + "_lnkbtn1_addtolist1";
                                    FavIdList1 += ":" + "#" + e.Item.ClientID + "_lnkbtn1_addtolist2";
                                }
                            }
                            //ListIdDescription = row["ListName"].ToString();
                        }
                    }

}
protected void DataGrid2_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                try
                {
                    string itemID = ((DataRowView)e.Item.DataItem).Row["ItemId"].ToString().Trim();
                    string itemType = ((DataRowView)e.Item.DataItem).Row["ItemType"].ToString().Trim();
                    bool CanBeOrderedOnline = Convert.ToBoolean(((DataRowView)e.Item.DataItem).Row["CanBeOrderedOnline"].ToString().Trim());
                    bool isProductGroup = itemID.StartsWith("PG") ? true : false;


                    string ItemIdFav = "";

                    string sqlQuery2 = string.Format(" select ItemId from e2wListItem where ListId in (select top 1 ListId from e2wList where ListName='My Favourite') and CreatedBy='" + signOn.User.UserId.Trim() + "' order by SeqNo");
                    DataSet dsLists2 = new DataSet();
                    if (DBtools.GetDataset(sqlQuery2, "e2wList2", ref dsLists2))
                    {
                        foreach (DataRow row in dsLists2.Tables[0].Rows)
                        {
                            ItemIdFav = row["ItemId"].ToString();
                            if (ItemIdFav.Trim().Equals(itemID))
                            {
                                if (string.IsNullOrEmpty(FavIdList2) || string.IsNullOrEmpty(FavIdList2))
                                {
                                    // FavIdList = "#" + e.Item.ClientID + "_lnkbtn1_addtolist1";
                                    FavIdList2 = "#" + e.Item.ClientID + "_lnkbtn1_addtolist3";
                                }
                                else
                                {
                                    // FavIdList += ":" + "#" + e.Item.ClientID + "_lnkbtn1_addtolist1";
                                    FavIdList2 += ":" + "#" + e.Item.ClientID + "_lnkbtn1_addtolist3";
                                }
                            }
                            //ListIdDescription = row["ListName"].ToString();
                        }
                    }


}

No comments:

Post a Comment