Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 27th, 2010, 06:39 AM
Authorized User
 
Join Date: Jan 2010
Posts: 34
Thanks: 5
Thanked 0 Times in 0 Posts
Default Linq paging Question

hi
I created a simple page with dropdownlist which holds categories of items
- category 1

also I have a tree view of category 2 of items

also I placed a grid view on the page with no datasource associated with it.

when the dropdownlist selected index change I run a linq code to select the items where category1== the selected dropdownlist value and bind the results to the grid

when the tree view selected node change I run a linq code to select the items where category2==the selected treenode value and bind the results to the grid

thats works fine until I start paging - I get empty data when going to the next page (which we know has data since the grid pager show page 2,3...)

why is that?
does the linq code is good just for the first bind and after that I need to handle the paging myself in code?

TIA
BARAK
 
Old January 27th, 2010, 09:42 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Maybe the new data overwrites the current state? Difficult to say without seeing any code.

Can you post the full, working code for this page?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old January 27th, 2010, 10:44 AM
Authorized User
 
Join Date: Jan 2010
Posts: 34
Thanks: 5
Thanked 0 Times in 0 Posts
Default here is the page code

thanks
I post the code:
I created linq dbml with some tables
the main of them is items from where I take the data for the grid

the init function are not so important - they just put the data in the treeview and dropdownlist in the first time the page is load
so we have the filters GUI objects.

ASPX:
Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title></title>
</head>
<body>
  <form id="form1" runat="server">
  <div>
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
      <ContentTemplate>
        <table width="100">
          <tr valign="top">
            <td width="20%">
              
              <asp:DropDownList ID="DropDownList1" runat="server" 
                AppendDataBoundItems="True" 
                AutoPostBack="True">
                <asp:ListItem Value="0">Select Designer:</asp:ListItem>
              </asp:DropDownList>
              
              <asp:TreeView ID="TreeView1" runat="server" ImageSet="Arrows">
                <ParentNodeStyle Font-Bold="True" />
                <HoverNodeStyle Font-Underline="True" ForeColor="#6D266A" />
                <SelectedNodeStyle Font-Underline="True" ForeColor="#6D266A" 
                 HorizontalPadding="0px"
                  VerticalPadding="0px" />
                <NodeStyle Font-Names="Tahoma" Font-Size="10pt" 
                ForeColor="#6D266A" HorizontalPadding="5px"
                  NodeSpacing="0px" VerticalPadding="0px" />
              </asp:TreeView>
            </td>
            <td width="80%">
              <asp:GridView ID="GridView1" runat="server"
               AllowPaging="True" AutoGenerateColumns="False" 
               DataKeyNames="item" >
                <Columns>
                  <asp:BoundField DataField="item" HeaderText="Item" ReadOnly="True" 
                    SortExpression="item" />
                  <asp:BoundField DataField="itemdesc" HeaderText="Description" 
                    SortExpression="itemdesc" />
                 </Columns>
              </asp:GridView>              
            </td>
          </tr>
        </table>
        </ContentTemplate>        
    </asp:UpdatePanel>
  </div>
  </form>
</body>
</html>
code behind (VB.NET):
Code:
Partial Class _Default
  Inherits System.Web.UI.Page

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not Page.IsPostBack Then
      Using mydata As New TreeTestDataContext()
        InitItemClassTree(mydata)
        InitDesigners(mydata)
      End Using
    End If
  End Sub
  Private Sub InitDesigners(ByRef aDataContext As TreeTestDataContext)
    Dim allDesigners = From d In aDataContext.designers _
                      Order By d.designer _
                      Select New With {d.id, d.designer}

    For Each d In allDesigners
      Dim newListItem As New ListItem
      newListItem.Value = d.id
      newListItem.Text = d.designer
      DropDownList1.Items.Add(newListItem)
    Next
  End Sub
  Private Sub InitItemClassTree(ByRef aDataContext As TreeTestDataContext)
    Dim allclasses = From c In aDataContext.itemclassesgroups _
                     Order By c.forder _
                     Select New With {c.id, c.name, c.itemclasses}

    For Each c In allclasses
      Dim newExpandNode As New TreeNode
      With newExpandNode
        .Text = c.name
        .Value = c.id
        .SelectAction = TreeNodeSelectAction.Expand
        .Expanded = False
        For Each i As itemclass In c.itemclasses
          Dim newSelectNode As New TreeNode
          With newSelectNode
            .SelectAction = TreeNodeSelectAction.Select
            .Text = i.itemclass
            .Value = i.id
          End With
          newExpandNode.ChildNodes.Add(newSelectNode)
        Next
      End With
      TreeView1.Nodes.Add(newExpandNode)
    Next
  End Sub

  Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
    Using mydata As New TreeTestDataContext
      Dim allItemsByDesignerId = From it In mydata.items _
                                  Where it.designerid = DropDownList1.SelectedValue _
                                  Order By it.sortorder _
                                  Select New With {it.item, it.itemdesc}
      GridView1.DataSource = allItemsByDesignerId
      GridView1.DataBind()
    End Using
  End Sub

  Protected Sub TreeView1_SelectedNodeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.SelectedNodeChanged
    Using mydata As New TreeTestDataContext
      Dim allItemsByClassId = From it In mydata.items _
                                  Where it.itemclassid = TreeView1.SelectedValue _
                                  Order By it.sortorder _
                                  Select New With {it.item, it.itemdesc}
      GridView1.DataSource = allItemsByClassId
      GridView1.DataBind()
    End Using
  End Sub
End Class
the error I am getting when pressing on the paging links (2 3 ...)
is this:
Code:
Line: 4723
Error: Sys.WebForms.PageRequestManagerServerErrorException: The GridView 'GridView1' fired event PageIndexChanging which wasn't handled.
what handeling I need to do here? isn't it suppose to be auomatically?

Thanks very much
BARAK
 
Old January 27th, 2010, 11:48 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Nope; not when manually binding data. Take a look at this:

Code:
 
  If Not Page.IsPostBack Then
     Using mydata As New TreeTestDataContext()
       InitItemClassTree(mydata)
       InitDesigners(mydata)
     End Using
   End If
You only bind data when the page does't post back. The GridView doesn't maintain all its data in ViewState (otherwise it would create too much overhead, and defeat the purpose of paging) so the data is gone after a Postback.

You can use a LinqDataSource and let the controls handle it, or read a bit more about implementing custom paging scenarios: http://www.google.nl/search?hl=nl&q=...&meta=&aq=f&oq=

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about LINQ maratin BOOK: ASP.NET MVC Website Programming Problem Design Solution ISBN: 9780470410950 3 January 24th, 2010 10:49 AM
Linq - A Design Question mikener LINQ 3 November 14th, 2009 10:47 AM
Migrating to Linq to Sql (pg. 16/18) question Rachel BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 January 19th, 2009 03:15 PM
LINQ question thangxii BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 6 July 6th, 2008 03:13 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.