470,849 Members | 1,112 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

Gridview viewstate failed to load error with too many rows!

1
Hi,

I am quite desperate now because I made a nice webshop with a gridview where the customer is able to update the amount of products (Hostas in my situation) or delete the row.
The problem is that every works really fine with this code when customers order approximatelly a maximum of 35 products.
What I learned so far is to set the EnableViewState="False" for all the labels that don't need a viewstate. This helped a lot.

What can I do to make this work for an unlimited order?

You help is very appreciated!!!!!

This is my code so far:
Expand|Select|Wrap|Line Numbers
  1. <asp:AccessDataSource id="AccessDataSource1" Runat="Server"
  2.     DataFile="<%$ connectionStrings: AccessHostaConnection %>"
  3.   OnSelected="Get_Rows"
  4.  
  5.   SelectCommand="SELECT * FROM ShopCart WHERE OrderNumber=@OrderNumber order by naam"
  6.  
  7.   UpdateCommand="UPDATE ShopCart SET Aantal=@Aantal
  8.                  WHERE OrderNumber=@OrderNumber AND HostaID=@HostaID"
  9.  
  10.   DeleteCommand="DELETE FROM ShopCart
  11.                  WHERE OrderNumber=@OrderNumber AND HostaID=@HostaID"
  12. >
  13.   <SelectParameters>
  14.     <asp:ControlParameter Name="OrderNumber" ControlId="OrderNumberLabel"
  15.     PropertyName="Text"/>
  16.   </SelectParameters>
  17.   <UpdateParameters>
  18.     <asp:ControlParameter Name="OrderNumber" ControlId="OrderNumberLabel"
  19.     PropertyName="Text"/>
  20.   </UpdateParameters>
  21.   <DeleteParameters>
  22.     <asp:ControlParameter Name="OrderNumber" ControlId="OrderNumberLabel"
  23.     PropertyName="Text"/>
  24.   </DeleteParameters>
  25.  
  26. </asp:AccessDataSource>
  27.  
  28. <asp:Label ID="Label1" Text="Hosta Shopcart" Font-Size="14pt" ForeColor="#8E001C" 
  29. Runat="Server"/> &nbsp;   <asp:hyperlink id="Catalogus" Text="Continue shopping" navigateUrl="nwcatalog2.aspx" runat="server"> </asp:hyperlink> 
  30.             <asp:Label ID="voorraad" runat="server" ></asp:Label>
  31.             <asp:Label ID="logtekstlabel" runat="server"></asp:Label>
  32. <table border="0">
  33. <tr>
  34.   <td><b>Order number: </b></td>
  35.   <td><asp:Label id="OrderNumberLabel" Runat="Server"/></td>
  36. </tr>
  37. </table>
  38. <table>
  39. <tr>
  40. <td>
  41.             <b>You can change the amount of Hostas by means of the &quot;Change&quot;-button per 
  42.             Hosta. Subsequently you can change the amount you wish to order and finally you 
  43.             need to confirm your change by the &quot;Update&quot;-button.</td>            
  44.  
  45. </tr>
  46. </table>
  47.  
  48. <asp:Label id="NoItemsMessage" Runat="Server"
  49.   Text="No Hostas in Shopcart" EnableViewState="False" Visible="False"
  50.   Width="206px" Height="1px" BackColor="#E0E0E0" ForeColor="#8E001C"
  51.   BorderStyle="Solid" BorderWidth="1px" BorderColor="Silver" 
  52.   Style="margin-top:10px; padding:15px"/>
  53.  
  54. <asp:Panel ID="Panel1" Width="700" Runat="Server"
  55. ForeColor="#990000" HorizontalAlign="Left">
  56.   <asp:Label id="ErrMessage" Text=" " EnableViewState="False" Runat="Server"/>
  57. </asp:Panel>
  58.  
  59. <asp:AccessDataSource id="ShopCartSource" Runat="Server"
  60.     DataFile="<%$ connectionStrings: AccessHostaConnection %>"
  61.   OnSelected="Get_Rows"
  62.  
  63.   SelectCommand="SELECT * FROM ShopCart WHERE OrderNumber=@OrderNumber order by naam"
  64.  
  65.   UpdateCommand="UPDATE ShopCart SET Aantal=@Aantal
  66.                  WHERE OrderNumber=@OrderNumber AND HostaID=@HostaID"
  67.  
  68.   DeleteCommand="DELETE FROM ShopCart
  69.                  WHERE OrderNumber=@OrderNumber AND HostaID=@HostaID"
  70. >
  71.   <SelectParameters>
  72.     <asp:ControlParameter Name="OrderNumber" ControlId="OrderNumberLabel"
  73.     PropertyName="Text"/>
  74.   </SelectParameters>
  75.   <UpdateParameters>
  76.     <asp:ControlParameter Name="OrderNumber" ControlId="OrderNumberLabel"
  77.     PropertyName="Text"/>
  78.   </UpdateParameters>
  79.   <DeleteParameters>
  80.     <asp:ControlParameter Name="OrderNumber" ControlId="OrderNumberLabel"
  81.     PropertyName="Text"/>
  82.   </DeleteParameters>
  83.  
  84. </asp:AccessDataSource>
  85.  
  86. <asp:GridView id="ShopCartGrid" DataSourceID="ShopCartSource" Runat="Server"
  87.   AutoGenerateColumns="False"
  88.   DataKeyNames="OrderNumber,HostaID" 
  89.   onrowupdating="Shopcart_RowUpdating"
  90.   onrowdeleting="Shopcart_Rowdeleting"
  91.   Cellpadding="3"
  92.   ShowFooter="True"
  93. >
  94.   <Columns>
  95.  
  96.   <asp:TemplateField
  97.     HeaderText="Name" HeaderStyle-HorizontalAlign="Left" 
  98.     ItemStyle-Width="150">
  99.     <ItemTemplate>
  100.       <asp:Label ID="Label4" Runat="Server" EnableViewState="False" 
  101.         Text='<%# Bind("Naam") %>'/>
  102.     </ItemTemplate>
  103.     <EditItemTemplate>
  104.       <asp:Label ID="Label5" Runat="Server" EnableViewState="False" 
  105.         Text='<%# Bind("Naam") %>'/>
  106.     </EditItemTemplate>
  107.     </asp:TemplateField>
  108.  
  109.   <asp:TemplateField
  110.     HeaderText="Photo" HeaderStyle-HorizontalAlign="Left" 
  111.     ItemStyle-Width="50">
  112.      <ItemTemplate>
  113.         <asp:Image ImageUrl='<%# Eval("Naam", "http://www.hostaparadise.com/images/thumbs/{0}.jpg") %>' EnableViewState="False"  runat="server"/>
  114.     </ItemTemplate>
  115.   </asp:TemplateField>
  116.  
  117.   <asp:TemplateField
  118.     HeaderText="Price"
  119.     ItemStyle-HorizontalAlign="Right" 
  120.     ItemStyle-Width="50">
  121.     <ItemTemplate>
  122.       <asp:Label ID="Label6" Runat="Server" EnableViewState="False" 
  123.         Text='<%# String.Format("€ {0:C},00", Eval("Prijs")) %>'/>
  124.     </ItemTemplate>
  125.     <EditItemTemplate>
  126.       <asp:Label ID="Label7" Runat="Server" EnableViewState="False" 
  127.         Text='<%# String.Format("€ {0:C},00", Eval("Prijs")) %>'/>
  128.     </EditItemTemplate>
  129.   </asp:TemplateField>
  130.  
  131.   <asp:TemplateField
  132.     HeaderText="Number" 
  133.     ItemStyle-Width="60"
  134.     FooterStyle-HorizontalAlign="Right"
  135.     ItemStyle-HorizontalAlign="Right">
  136.     <ItemTemplate>
  137.       <asp:Label ID="Label8" Runat="Server" EnableViewState="False" 
  138.         Text='<%# String.Format("{0:D}", Eval("Aantal")) %>'
  139.         Width="25" Font-Size="9pt" Style="text-align:right"/>
  140.     </ItemTemplate>
  141.     <EditItemTemplate>
  142.       <asp:TextBox id="Number" Runat="Server" EnableViewState="False" 
  143.         Text='<%# Bind("Aantal") %>'
  144.         MaxLength="4" Width="25" Height="17" Font-Size="9pt"
  145.         Style="padding:0px; text-align:right"/>
  146.  
  147.     </EditItemTemplate>
  148.  
  149.     <FooterTemplate>
  150.       <asp:Label ID="Label10" Text="Total" Runat="Server" EnableViewState="False"
  151.         Font-Bold="True" Width="50" BorderStyle="Solid" BorderWidth="0" 
  152.         Style="padding:2px; margin-top:5px"/>
  153.     </FooterTemplate>
  154.   </asp:TemplateField>
  155.  
  156.  
  157.   <asp:TemplateField HeaderText="Amount" 
  158.     ItemStyle-Width="80"
  159.     ItemStyle-HorizontalAlign="Right"
  160.     FooterStyle-HorizontalAlign="Right">
  161.     <ItemTemplate>
  162.       <asp:Label ID="Label11" Runat="Server" EnableViewState="False" 
  163.         Text='<%# String.Format("{0:C}", _
  164.                   Get_Amount(Eval("Prijs"), Eval("Aantal"))) %>'/>
  165.     </ItemTemplate>
  166.     <EditItemTemplate>
  167.       <asp:Label ID="Label12" Runat="Server" EnableViewState="False" 
  168.         Text='<%# String.Format("{0:C}", _
  169.                   Get_Amount(Eval("Prijs"), Eval("Aantal"))) %>'/>
  170.     </EditItemTemplate>
  171.     <FooterTemplate>
  172.       <asp:Label id="OrderTotal" Runat="Server"
  173.         Text='<%# String.Format("{0:C}", Get_Order_Total()) %>' 
  174.         Width="80" Font-Bold="True" BorderStyle="Solid" BorderWidth="1"
  175.         BorderColor="#C0C0C0" Style="padding:2px; margin-top:5px"/>
  176.     </FooterTemplate>
  177.   </asp:TemplateField>
  178.  
  179.   <asp:TemplateField
  180.     HeaderText="Modify order"
  181.     ItemStyle-Width="110"
  182.     FooterStyle-BackColor="#E0E0E0">
  183.     <ItemTemplate>
  184.       <asp:Button ID="Button1" Text="Change" CommandName="Edit" Runat="Server"
  185.         Font-Size="7pt" Width="50"/>
  186.       <asp:Button ID="Button2" Text="Delete" CommandName="Delete" Runat="Server"
  187.         Font-Size="7pt" Width="50"/>
  188.     </ItemTemplate>
  189.     <EditItemTemplate>
  190.       <asp:Button ID="Button3" Text="Update" CommandName="Update" Runat="Server"
  191.         Font-Size="7pt" Width="50"/>
  192.       <asp:Button ID="Button4" Text="Cancel" CommandName="Cancel" Runat="Server"
  193.         Font-Size="7pt" Width="50"/>
  194.     </EditItemTemplate>
  195.     <FooterTemplate>
  196.       <asp:Button ID="Button5" Text="Finalise order »" OnClick="Submit_Form"  EnableViewState="False" Runat="Server" Font-Size="8pt" Width="75" Style="margin-top:22px"/>
  197.  
  198.     </FooterTemplate>
  199.   </asp:TemplateField>
  200.  
  201.   </Columns>
  202.  
  203. </asp:GridView>
  204.  
  205.  
  206.   </form>
  207. </body>
  208. </html>
Mar 17 '08 #1
0 1832

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Eamonn O'Connell | last post: by
9 posts views Thread by John Kirksey | last post: by
6 posts views Thread by hitendra15 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.