User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 391,588 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,656 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 591 | Replies: 0
Reply
Join Date: Jun 2008
Posts: 3
Reputation: saquib189 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
saquib189 saquib189 is offline Offline
Newbie Poster

Paging in datalist

  #1  
Jun 18th, 2008
Hi all i have a datalist and i enable paging in it. but the link button not work when i click on it. The code is shown below:

  1. <asp:Panel ID="Panel2" runat="server">
  2.  
  3. <font size="-1" face="Verdana, Arial, Helvetica, sans-serif"><asp:label id="pageNumber" runat="server" /></font>
  4.  
  5. <asp:DataList ID="theDataList" runat="server" RepeatColumns="4" Width="616px" CellPadding="4" ForeColor="#333333">
  6.  
  7. <HeaderTemplate>
  8.  
  9. Book Listing
  10.  
  11. </HeaderTemplate>
  12.  
  13.  
  14.  
  15. <ItemTemplate>
  16.  
  17. <asp:Image ID="Image1" Width="100" Height="100" Runat="Server"
  18.  
  19. AlternateText='<%# "Picture of " & Eval("image") %>'
  20.  
  21. ImageUrl='<%# "images/" & Eval("image") & ".jpg" %>' />
  22. <br /><br />
  23.  
  24. <asp:HyperLink ID="HyperLink2" Runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"BookTitle") %>' NavigateUrl='<%# "Details.aspx?BookID=" & Container.DataItem("BookID") %>' />
  25.  
  26. </ItemTemplate>
  27.  
  28. <ItemStyle HorizontalAlign="Center" BackColor="#EFF3FB" />
  29.  
  30. <SeparatorStyle BackColor="Maroon" BorderStyle="Dotted" />
  31.  
  32. <HeaderStyle BackColor="#507CD1" Font-Bold="True" Font-Size="12pt" ForeColor="White"
  33.  
  34. HorizontalAlign="Center" />
  35.  
  36. <FooterStyle BackColor="#507CD1" ForeColor="White" Font-Bold="True" />
  37.  
  38. <SelectedItemStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
  39.  
  40. <AlternatingItemStyle BackColor="White" />
  41.  
  42.  
  43.  
  44.  
  45.  
  46. </asp:DataList>
  47.  
  48. <asp:LinkButton id="btnPrev" Text="Prev" OnClick="Prev_Click" runat="server" />
  49.  
  50.  
  51.  
  52. <asp:LinkButton id="btnNext" Text="Next" OnClick="Next_Click" runat="server" />
  53. </asp:Panel>

and vb code:

  1. Private pagedData As New PagedDataSource()
  2.  
  3.  
  4.  
  5.  
  6. Public Function getTheData() As DataTable
  7.  
  8.  
  9. Dim DS As New DataSet()Dim myConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("SecurityTutorialsConnectionString").ConnectionString)
  10.  
  11.  
  12. Dim objSQLAdapter As New SqlDataAdapter("SELECT * FROM BooksDB", myConnection)
  13.  
  14. objSQLAdapter.Fill(DS, "BooksDB")
  15.  
  16.  
  17.  
  18.  
  19. Return DS.Tables(0)
  20.  
  21.  
  22. End Function
  23.  
  24. Private Sub doPaging()
  25.  
  26.  
  27. pagedData.DataSource = getTheData().DefaultView
  28.  
  29.  
  30.  
  31. pagedData.AllowPaging = True
  32.  
  33. pagedData.PageSize = 20
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41. Try
  42.  
  43. pagedData.CurrentPageIndex = Int32.Parse(Request("Page").ToString())Catch ex As Exception
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56. pagedData.CurrentPageIndex = 0
  57.  
  58. End Try
  59.  
  60.  
  61.  
  62. btnPrev.Visible = (Not pagedData.IsFirstPage)
  63.  
  64.  
  65. btnNext.Visible = (Not pagedData.IsLastPage)
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72. theDataList.DataSource = pagedData
  73.  
  74.  
  75.  
  76. theDataList.DataBind()
  77.  
  78.  
  79.  
  80. End Sub
  81.  
  82. Private Sub Prev_Click(ByVal obj As Object, ByVal e As EventArgs)
  83.  
  84.  
  85. Response.Redirect(Request.CurrentExecutionFilePath + "?Page=" + (pagedData.CurrentPageIndex - 1))
  86. End Sub
  87.  
  88. Private Sub Next_Click(ByVal obj As Object, ByVal e As EventArgs)
  89.  
  90.  
  91. Response.Redirect(Request.CurrentExecutionFilePath + "?Page=" + (pagedData.CurrentPageIndex + 1))
  92. End Sub
  93.  
  94. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
  95.  
  96. doPaging()

End Sub

Thank you
Last edited by peter_budo : Jun 20th, 2008 at 8:55 am. Reason: Keep It Organized - please use [code] tags
AddThis Social Bookmark Button
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb ASP.NET Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 11:04 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC