Click here to Skip to main content
12,241,564 members (49,991 online)
Rate this:
 
Please Sign up or sign in to vote.
I am creating a wall using a UserControl ( which is a nested GridView) i want to load the rows of the GridView on scrolling down just like facebook. I am trying to implement this method.. Click MeClick here The example seems to read the last row's first column to get the last row which is loaded and to fetch next bunch of rows. I added a bound field to my UserControl's GridView but i guess i am not able to read the right value since i am getting error "Input string was not in a correct format." at ..

protected void btnGetMoreRecords_Click(object sender, EventArgs e)
    {
        //Fetch 14 records initially.
        dt = dbo.FetchNextProducts(Convert.ToInt32(hiddenLastProductID.Value), 14, 42);

Its Convert.ToInt32(hiddenLastProductID.Value where i am getting the error.

and this is my aspx code of the usercontrol..

<asp:ScriptManager ID="sm1" runat="server">
        <Scripts>
            <asp:ScriptReference Path="~/ScriptsScroll/jquery-1.4.1.js" />
        </Scripts>
    </asp:ScriptManager>
 
    <div id="divProducts" style="height:700px;overflow-x:hidden;overflow-y: scroll;">
 
<table cellpadding="0" cellspacing="1" border="0">
    <tr>
        <td align="left">
            <asp:GridView ID="GridViewUserScraps" ItemStyle-VerticalAlign="Top" AutoGenerateColumns="False"
                GridLines="None" Width="100%" ShowHeader="False" runat="server" AlternatingRowStyle-BackColor="#A5A5A5"
                CellPadding="4" ForeColor="#333333" DataKeyNames="ScrapId" OnRowCommand="GridViewRowCommand">
                <Columns>
 
                    <asp:BoundField DataField="id" />
 
                    <asp:TemplateField>
 
                        <FooterTemplate>
 
                            <asp:LinkButton ID="LinkButton1" runat="server">Load More</asp:LinkButton>
 
                        </FooterTemplate>
                        <ItemTemplate>
                            <table align="left" cellpadding="1" cellspacing="2">
                                <tr>
                                    <td>
                                        <a href='<%#getUserHREF(Container.DataItem)%>'>
                                            <img align="middle" src='<%#getSRC(Container.DataItem)%>' border="0" width="50px" />
Posted 16-Apr-13 22:55pm
Edited 16-Apr-13 23:16pm
v2
Comments
johannesnestler 17-Apr-13 4:21am
   
Let the Debugger run and look what hiddenLastProductID.Value is when you get that exception. Should be easy to figure out why this string is not convertible to an Int32.

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Check the value of your hiddenfield before converting it to integer. This problem may occur due to an empty string in HiddenField.
Try this:
protected void btnGetMoreRecords_Click(object sender, EventArgs e)
{
    if(hiddenLastProductID.Value.Trim() != ""){
        //Fetch 14 records initially.
        dt = dbo.FetchNextProducts(Convert.ToInt32(hiddenLastProductID.Value.Trim()), 14, 42);
    }
}


--Amit
  Permalink  
Comments
arbaaz jalil 17-Apr-13 4:44am
   
Yup it is Null its empty but how can i solve it? why is it empty?
_Amy 17-Apr-13 4:53am
   
That can be solved by you only. Put a breakpoint and debug the code. You, probably will able to find the causes which is making your HiddenField null or empty. Good Luck!
arbaaz jalil 17-Apr-13 5:04am
   
I think its because it is unable to detect the value within td which is generated on runtime by the nested gridview.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160426.1 | Last Updated 17 Apr 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100