Thursday, August 22, 2019

Replace Repeater control href url value to new value jquery


    <script>
        $(document).ready(function () {


  try {

                $("a[id*=someid_Repeater1]").each(function () {
                    var oldUrl = $(this).attr("href"); // Get current url
                    var newUrl = oldUrl.replace("userControls/", ""); // Create new url
                    $(this).attr("href", newUrl); // Set herf value
                });
                
            } catch (err) {
                //  alert("error");
            }
        });
   </script>

Sample repeater code
 <asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
                <ItemTemplate>
                    <div class="product-item">
                        <div class="product-item-image-wrapper">
                            <div class="product-item-image-container">
                                <asp:HyperLink ID="ImgNavigateUrl" runat="server"  NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "ContainerCategoryUrl") %>'>
                                    <asp:Image ID="ImgThumbNailUrl" runat="server" Style="max-height: 100px; max-width: 100px;" AlternateText='<%# DataBinder.Eval(Container.DataItem, "ContainerCategoryImage") %>'></asp:Image>
                                </asp:HyperLink>
                            </div>
                        </div>
                        <div class="product-item-meta-container">
                            <asp:HyperLink ID="HyperURL" runat="server"  NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "ContainerCategoryUrl") %>' >  <asp:Label ID="Label1" runat="server"  Text='Browse' CssClass="browse"></asp:Label>    </asp:HyperLink>
                                  <asp:Panel runat="server" ID="pnlMoreContent">
                                <ul class="product-meta">
                                    <li> <asp:HyperLink ID="HyperCategoryName" runat="server" CssClass="browse-text" NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "ContainerCategoryUrl") %>' > <%# DataBinder.Eval(Container.DataItem, "CategoryName")%>     </asp:HyperLink></li>
                                  <%-- <li><%# DataBinder.Eval(Container.DataItem, "CategoryId")%></li>--%>
                                    <li></li>
                                </ul>
                            </asp:Panel>
                        </div>
                    </div>
                </ItemTemplate>
            </asp:Repeater>

 protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                try
                {
                    string CategoryId = ((DataRowView)e.Item.DataItem).Row["CategoryId"].ToString().Trim();
                    string CategoryName = ((DataRowView)e.Item.DataItem).Row["CategoryName"].ToString().Trim();
                    string OnlineSpecialContainer = "";
                    string OnlineSpecialCategory = "";

                    List<SqlParameter> sqlParamsCategory = new List<SqlParameter>();
                    sqlParamsCategory.Add(DBtools.GetSqlParameterObject("@Lang", DBtools.STRING_TYPE, 5, Profile.culture, 0, 0));
                    string strOnlineSpecialCategory = " select top 1 ContainerId from ssCategoryContainer where   ContainerName =(select top 1 CategoryName from ssCategory where CategoryId='" + CategoryId + "') ";
                    string AppendUrl = "";
                    string[] record = DBtools.GetRecord(strOnlineSpecialCategory, sqlParamsCategory);
                    if (record != null && record.Length > 0)
                    {
                        // retVal = GetNavigateUrl(record[0]);//HttpContext.Current.Request.ApplicationPath + "/" + record[0];
                        if (record[0] != null)
                        {
                            OnlineSpecialContainer = record[0];
                        }
                        if (CategoryId != null)
                        {
                            OnlineSpecialCategory = CategoryId;
                        }
                        if (CategoryName.ToLower().Trim().Equals("online specials"))
                    {
                        AppendUrl = "?parentId=&Category&parentLink=&Container:&Category&HomePage=true";
                        }
                        else
                        {

                            AppendUrl = "?parentId=&Container&parentLink=&Container";
                        }
                    }



                    // string AppendUrl = "e2wShoppingCatalog.aspx?parentId=&Category&parentLink=&Container:&Category";
                  
                    //   bool CanBeOrderedOnline = Convert.ToBoolean(((DataRowView)e.Item.DataItem).Row["CanBeOrderedOnline"].ToString().Trim());
                    //   string itemType = ((DataRowView)e.Item.DataItem).Row["ItemType"].ToString().Trim();
                    //  string uom = string.Empty;

                    //  bool isProductGroup = itemID.StartsWith("PG") ? true : false;

                  
                        HyperLink hLink = (HyperLink)e.Item.FindControl("ImgNavigateUrl");

                        if (hLink != null)
                        {
                            hLink.Attributes.Add("onclick", "ProcessingWait(false);");
                            string navigateUrl = ((DataRowView)e.Item.DataItem).Row["ContainerCategoryUrl"].ToString().Trim();
                            navigateUrl += AppendUrl;
                            navigateUrl = navigateUrl.Replace("&Category", OnlineSpecialCategory);
                            navigateUrl = navigateUrl.Replace("&Container", OnlineSpecialContainer);
                            if (!string.IsNullOrEmpty(AppendUrl))
                            {
                                hLink.NavigateUrl = navigateUrl;
                            }
                            else
                            {
                                hLink.NavigateUrl = "";
                            }
                        }
                        HyperLink HyperURL = (HyperLink)e.Item.FindControl("HyperURL");
                        if (HyperURL != null)
                        {
                            HyperURL.Attributes.Add("onclick", "ProcessingWait(false);");
                            string navigateUrl = ((DataRowView)e.Item.DataItem).Row["ContainerCategoryUrl"].ToString().Trim();
                            navigateUrl += AppendUrl;
                            navigateUrl = navigateUrl.Replace("&Category", OnlineSpecialCategory);
                            navigateUrl = navigateUrl.Replace("&Container", OnlineSpecialContainer);
                            if (!string.IsNullOrEmpty(AppendUrl))
                            {
                                HyperURL.NavigateUrl = navigateUrl;
                            }
                            else
                            {
                                HyperURL.NavigateUrl = "";
                            }

                        }

                        HyperLink HyperCategoryName = (HyperLink)e.Item.FindControl("HyperCategoryName");
                        if (HyperCategoryName != null)
                        {
                            HyperCategoryName.Attributes.Add("onclick", "ProcessingWait(false);");
                            string navigateUrl = ((DataRowView)e.Item.DataItem).Row["ContainerCategoryUrl"].ToString().Trim();
                            navigateUrl += AppendUrl;
                            navigateUrl = navigateUrl.Replace("&Category", OnlineSpecialCategory);
                            navigateUrl = navigateUrl.Replace("&Container", OnlineSpecialContainer);
                            if (!string.IsNullOrEmpty(AppendUrl))
                            {
                                HyperCategoryName.NavigateUrl = navigateUrl;
                            }
                            else
                            {
                                HyperCategoryName.NavigateUrl = "";
                            }

                        }
                   

                    Image hImage = (Image)e.Item.FindControl("ImgThumbNailUrl");
                    string imgName = ((DataRowView)e.Item.DataItem).Row["ContainerCategoryImage"].ToString().Trim();
                    hImage.ImageUrl = CatalogUtility.GetImageUrl(imgName);


                }
                catch (Exception ex)
                {
                    LogWriter.Error(ex.Message, ex);
                }
            }
        }

//Page load some binding code
  Repeater1.DataSource = dtDisplay;
                Repeater1.DataBind();

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();
                        }
                    }


}

Show paging count Jquery

aspx


    $(document).ready(function () {
 try {

            if ("<%=ItemcountRepeater%>" > 0) {


                var label_text = $('#ctl00_CustomerMainContent_e2wItemLayout1_lbl1_ShowingItemCount').text(); //Get the text
                label_text = label_text.replace("&1", "<%=ItemcountRepeaterPagerValue%>");
                label_text = label_text.replace("&2", "<%=ItemcountRepeater%>");
                //  $('#ctl00_CustomerMainContent_e2wItemLayout1_lbl1_ShowingItemCount').text(label_text.replace("&1", "<%=ItemcountRepeaterPagerValue%>"));
                // $('#ctl00_CustomerMainContent_e2wItemLayout1_lbl1_ShowingItemCount').text(label_text.replace("&2", "<%=ItemcountRepeater%>"));
                //alert("<%=ItemcountRepeaterPagerValue%>");
                //  var str = "Showing " + "<%=ItemcountRepeaterPagerValue%>" + " of " + "<%=ItemcountRepeater%>" + " results";
                $("#ctl00_CustomerMainContent_e2wItemLayout1_lbl1_ShowingItemCount").text(label_text);

            } else {
                $("#ctl00_CustomerMainContent_e2wItemLayout1_lbl1_ShowingItemCount").text("");
            }
        }
        catch (err) {
            $("#ctl00_CustomerMainContent_e2wItemLayout1_lbl1_ShowingItemCount").text("");
        }
 });


<asp:Label ID="lbl1_ShowingItemCount" runat="server" Text="Showing 1-30 of 200 results"></asp:Label>

<asp:Repeater ID="pagerTop" runat="server" EnableTheming="False"                         OnItemDataBound="Pager_ItemDataBound">
                        <ItemTemplate>
                            <asp:LinkButton ID="btnPage" CommandName="Page" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "pagerValue") %>'
                                Text='<%# DataBinder.Eval(Container.DataItem, "pagerText") %>' runat="server"></asp:LinkButton>
                        </ItemTemplate>
                    </asp:Repeater>


aspx.cs

 public int ItemcountRepeater = 1;
        public string ItemcountRepeaterPagerValue = "";
public string strShoppingCatalogDisplayItems = "";

  protected void Pager_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {

            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {

 if (ItemcountRepeater < Convert.ToInt32(strShoppingCatalogDisplayItems))
                {
                    ItemcountRepeaterPagerValue = "1-" + ItemcountRepeater;
                }
                else
                {
                    int paging = Convert.ToInt32(Session["spageIndex"].ToString().Trim()) + 1;
                    int totalitems = 0;
                    if (ItemcountRepeater > Convert.ToInt32(strShoppingCatalogDisplayItems))
                    {
                        totalitems = (paging * Convert.ToInt32(strShoppingCatalogDisplayItems));

                        if (ItemcountRepeater < totalitems)
                        {
                            ItemcountRepeaterPagerValue = (((paging - 1) * Convert.ToInt32(strShoppingCatalogDisplayItems)) + 1) + "-" + ItemcountRepeater;
                        }
                        else
                        {
                            int result = ((paging - 1) * Convert.ToInt32(strShoppingCatalogDisplayItems));
                            result = 0 + 1;
                            ItemcountRepeaterPagerValue = result + "-" + totalitems;
                        }
                    }

                }

                if (ItemcountRepeater < 1)
                {
                    ItemcountRepeaterPagerValue = "0";
                }
            }

//Datatable load

 if (dtDisplay.Rows.Count > 0)
            {
                ItemcountRepeater = dtDisplay.Rows.Count;

                if (ItemcountRepeater < Convert.ToInt32(strShoppingCatalogDisplayItems))
                {
                    ItemcountRepeaterPagerValue = "1-" + ItemcountRepeater;
                }
                if (ItemcountRepeater > Convert.ToInt32(strShoppingCatalogDisplayItems))
                {

                }

}

//load default value from defined parameters
if (!string.IsNullOrEmpty(ConfigParameters.GetParameterValue("ShoppingCatalogDisplayItems")))             {
                strShoppingCatalogDisplayItems = ConfigParameters.GetParameterValue("ShoppingCatalogDisplayItems").Trim();
                ddlListPerPage.SelectedValue = strShoppingCatalogDisplayItems;
            }
            else
            {
                strShoppingCatalogDisplayItems = "30";
                ddlListPerPage.SelectedValue = "30";
            }

On Hover of div Show another div

aspx page changes

//css

.MyAccountdiv {
    width:35%;
    padding:5px 8px;
    /*margin-left:20%;*/
    display:inline-block;
    background:#ededed;
    float:right;
    cursor:pointer;
}
#MyAccountdiv {
}
.MyAccount {
    color:#2f71a9;
    background: url("/Web/App_Themes/default/images/darrow.png") #ededed no-repeat center right 5px;
    }
.MyAccountbtn {
    color: #424242;
    text-align:left;
    width:100%;
    font-weight: normal;
    border:0px;
    background:#ededed;
}

<script type="text/javascript">

    function myFunction() {
        var x = document.getElementById("<%=Account_list.ClientID %>");
                    x.style.display = "block";
           }
    function myFunctionout() {
        var x = document.getElementById("<%=Account_list.ClientID %>");
                  x.style.display = "none";
       
    }
</script>

 <div runat="server" id="DivMyAccount" class="MyAccountdiv" onmouseover="javascript:myFunction();" onmouseout="javascript:myFunctionout();" >
                        <div id="MyAccountdiv" runat="server"  class="MyAccountbtn">
                            <div>My</div>
                            <div class="MyAccount">Account</div>
                        </div>
                    </div>
                    <div runat="server" id="Account_list" class="Account_list" onmouseover="javascript:myFunction();" onmouseout="javascript:myFunctionout();"></div>



aspx.cs page changes

//Load data to the div which will be visisble to customer on hover

 StringBuilder sQuery = new StringBuilder();
            sQuery.AppendFormat("SELECT RTRIM(CDCValue) AS CDCValue, RTRIM(CDCValueDesc) AS CDCValueDesc FROM {0}  where CDCCode = 'MyAccountList' and Lang = '{1}' order by CDCValue desc ", E2WConstants.SSTables.CDC_DETAIL, Profile.culture);
            //if (string.IsNullOrEmpty(Address.GetERPAdrressIDForCustomerItemNumber(signOn)))
            //{
            //    sQuery.Append(" and ColumnName <> 'CustomerMaterialNumber'");
            //}
            // sQuery.AppendFormat(" Union Select '{0}' AS CDCValue, '{0}' CDCValueDesc ", E2WConstants.SearchAutoComplete.ALLCOLUMN);
            DataTable dt = DBtools.GetDataTable(sQuery.ToString(), "CDCValues");

         
            if (dt != null && dt.Rows.Count > 0)
            {
              
                    StringBuilder sbInnerHtml = new StringBuilder();

                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                     

                        //sbInnerHtml.AppendFormat("<li><a href={0}></a></li>", dt.Rows[i][1].ToString());

                        sbInnerHtml.AppendFormat("<li><a href=\"{0}\" {2}>{1}</a></li>", dt.Rows[i][1].ToString(), dt.Rows[i][0].ToString(), "");
                    }

                    // MyAccount.InnerHtml  = sbInnerHtml.ToString();
                    Account_list.InnerHtml = sbInnerHtml.ToString();
            }