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

No comments:

Post a Comment