Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using infinite scroll in my application.. I am binding three fields from database :
1. Id
2. Imageurl
3. product_name

Infinite scroll is working totally fine.. All three fields data is showing on the first attempt.. but the problem is coming when the data attached after the scroll.. after scrolling only two fields are showing id and product_name.. Imageurl is not showing after the scroll... I am trying so hard from past 2 days to solve the problem... But i am not able to sort it out.. i tried almost everthing... Now, i am here to get help from you guyz.. hope you will help me to sort out my problem..

Here is my Jquery Code :
JavaScript
<pre lang="cs"><script type="text/javascript">
    var pageIndex = 1;
    var pageCount;
    $(window).scroll(function () {
        if ($(window).scrollTop() == $(document).height() - $(window).height()) {
            GetRecords();
        }
    });
    function GetRecords() {
        pageIndex++;
        if (pageIndex == 2 || pageIndex <= pageCount) {
            $("#loader").show();
            $.ajax({
                type: "POST",

                url: '<%= Page.ResolveUrl("~/Products.aspx/GetCustomers")%>',
                data: '{pageIndex: ' + pageIndex + '}',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: OnSuccess,
                failure: function (response) {
                    alert(response.d);
                },
                error: function (response) {
                    alert(response.d);
                }
            });
        }
    }
    function OnSuccess(response) {
        var xmlDoc = $.parseXML(response.d);
        var xml = $(xmlDoc);
        pageCount = parseInt(xml.find("PageCount").eq(0).find("PageCount").text());
        var customers = xml.find("add_product");
        customers.each(function () {
            var customer = $(this);
            var div = $("#dvCustomers div").eq(0).clone(true);

            $(".product_name", div).html(customer.find("Product_name").text());
            $(".imageurl", div).html(customer.find("Imageurl").text());

            $(".id", div).html(customer.find("ID").text());



            $("#dvCustomers").append(div).append("<br />");
        });
        $("#loader").hide();
    }
</script>




Below is the Html :
XML
<div id="dvCustomers">
        <asp:Repeater ID="rptCustomers" runat="server">
            <ItemTemplate>
            <div>
            <span class="imageurl"><%# Eval("Imageurl") %></span><br />
                             <span class="id"><%# Eval("Id") %></span><br />
                            <span class="product_name"><%# Eval("Product_name") %></span><br /><br />
                          </div>
            </ItemTemplate>
        </asp:Repeater>
    </div>

<div><img id="loader" alt="" src="images/loading.gif" style="display: none" /></div>


Here is my Code behind :
C#
  protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            rptCustomers.DataSource = GetCustomersData(1);
            rptCustomers.DataBind();
        }
        
}

    public static DataSet GetCustomersData(int pageIndex)
    {
        int pageSize = 12;
        int pagecount = 100;
        string query = "select * from (select ROW_NUMBER() OVER (ORDER BY product_name) rn ,* from add_product) a where rn BETWEEN(@PageIndex -1) * @PageSize + 1 AND(((@PageIndex -1) * @PageSize + 1) + @PageSize) - 1";
       

        SqlCommand cmd = new SqlCommand(query);
        cmd.CommandType = CommandType.Text;
        cmd.Parameters.AddWithValue("@PageIndex", pageIndex);
        cmd.Parameters.AddWithValue("@PageSize", pageSize);
        cmd.Parameters.AddWithValue("@PageCount", pagecount);
        return GetData(cmd);
    }
    private static DataSet GetData(SqlCommand cmd)
    {
        string strConnString = ConfigurationManager.ConnectionStrings["database_con"].ConnectionString;
        using (SqlConnection con = new SqlConnection(strConnString))
        {
            using (SqlDataAdapter sda = new SqlDataAdapter())
            {
                cmd.Connection = con;
                sda.SelectCommand = cmd;
                using (DataSet ds = new DataSet())
                {
                    sda.Fill(ds, "add_product");
                    DataTable dt = new DataTable("PageCount");
                    dt.Columns.Add("PageCount");
                    dt.Rows.Add();
                    dt.Rows[0][0] = cmd.Parameters["@PageCount"].Value;
                    ds.Tables.Add(dt);
                    return ds;
                }
            }
        }
    }

    [WebMethod]
    public static string GetCustomers(int pageIndex)
    {
        return GetCustomersData(pageIndex).GetXml();
    }
Posted
Comments
CHill60 23-Apr-15 19:24pm    
In which way is this different to your earlier post One field data is not showing after scoll[^]?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900