Do not use on any
shared computer
September 4, 2008 11:15pm pdt
 
[x]
Attachment Details

How do I bind data from SqlDb to a ListView & Binding Pagesize

Tags: asp.net
1. I need to populate ListView with the data from database from .vb ffile, not asp:SqlDataSource
2. i have no idea how to bind and implement Change Pagesize with DropDovnList
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
.aspx file  
 
  <div class="StatusMessage">
        <asp:Label ID="PageMessage" runat="server"></asp:Label>
    </div>
    
     <asp:DataPager ID="ProductListPagerSimple" runat="server" PagedControlID="ProductList" PageSize="5">
        <Fields>
            <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowNextPageButton="False"
                ShowPreviousPageButton="False" />
            <asp:NumericPagerField />
            
            <asp:NextPreviousPagerField ButtonType="Button" ShowLastPageButton="True" ShowNextPageButton="False"
                ShowPreviousPageButton="False" />
                  
        </Fields>
    </asp:DataPager>
    
    
   <asp:DataPager ID="ProductListPager" runat="server" PagedControlID="ProductList" PageSize="5">
        <Fields>
            <asp:TemplatePagerField>
                <PagerTemplate>
                    Jump to a specific page:
                    <asp:DropDownList runat="server" ID="PageJump" AutoPostBack="true" 
                        onselectedindexchanged="PageJump_SelectedIndexChanged">
                    </asp:DropDownList>
                </PagerTemplate>
            </asp:TemplatePagerField>
        </Fields>
    </asp:DataPager>
    
   
    
     <asp:DataPager ID="ProductListPagerCombo" runat="server" PagedControlID="ProductList" PageSize="5">
        
        <Fields>
            <asp:NextPreviousPagerField FirstPageText="&lt;&lt;" ShowFirstPageButton="True" 
                ShowNextPageButton="False" ShowPreviousPageButton="False" />
            <asp:NumericPagerField />
            
            <asp:NextPreviousPagerField LastPageText="&gt;&gt;" ShowLastPageButton="True" 
                ShowNextPageButton="False" ShowPreviousPageButton="False" />
        </Fields>
        
    </asp:DataPager>
         <br />
         
         
         Change Pagesize
         <asp:DropDownList ID="ddlChangePagesize" runat="server">
            
             <asp:ListItem Selected="True">5</asp:ListItem>
             <asp:ListItem>7</asp:ListItem>
             <asp:ListItem>10</asp:ListItem>
             <asp:ListItem>12</asp:ListItem>
             <asp:ListItem>15</asp:ListItem>
             <asp:ListItem>22</asp:ListItem>
         </asp:DropDownList>
          &nbsp;
         <asp:Button ID="Button1" runat="server" OnClick="RePage" Text="Change Pagesize" />&nbsp;<br />
         <br />
        
 
    
    
    
    
    
    
    
    <asp:ListView ID="ProductList" runat="server"  DataSourceID="SqlDataSource1">
        <LayoutTemplate>
            <h3>Product Listing</h3>
            <blockquote>
                <asp:PlaceHolder runat="server" ID="itemPlaceholder"></asp:PlaceHolder>                        
            </blockquote>
        </LayoutTemplate>
        
        <ItemSeparatorTemplate>
            <hr />
        </ItemSeparatorTemplate>
 
        <ItemTemplate>
        
            <h4><%#Eval("Naslov") %></h4>
            Available at <%#Eval("PostText")%> <br />
            dodano :  <%#Eval("Created")%>
            
        </ItemTemplate>
    </asp:ListView>
    
    
    
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DataAccessQuickStart %>"  
            SelectCommand="SELECT [IdPost], [UserID], [IdLang], [Created], [Naslov], [PostText], [Brojac], [ActivePost] FROM [ac_Posts] WHERE (([IdLang] = @IdLang) AND ([UserID] = @UserID)) ORDER BY [IdPost] DESC">
            <SelectParameters>
                <asp:Parameter DefaultValue="1" Name="IdLang" Type="Int32" />
                <asp:Parameter DefaultValue="1" Name="UserID" Type="Int32" />
                
            </SelectParameters>
            
        </asp:SqlDataSource>
    
           
----------------------------------------------------------------------------------------
.aspx.vb file
 
 Protected Sub ProductList_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles ProductList.DataBound
 
        Dim currentPage As Integer = (ProductListPager.StartRowIndex / ProductListPager.PageSize) + 1
        Dim totalPages As Integer = ProductListPager.TotalRowCount / ProductListPager.PageSize
        PageMessage.Text = String.Format("You are viewing page {0} of {1}", currentPage, totalPages)
 
        'Populate the DropDownList if needed
        Dim ddl As DropDownList = CType(ProductListPager.Controls(0).FindControl("PageJump"), DropDownList)
        If ddl.Items.Count = 0 Then
            'Add a list item for each page
            For i As Integer = 1 To totalPages
                ddl.Items.Add(i.ToString())
            Next
 
            'Set the DDL to the appropriate page value
            ddl.Items.FindByValue(currentPage.ToString()).Selected = True
        End If
    End Sub
 
 
 
    Protected Sub PageJump_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
 
        Dim PageJumpDDL As DropDownList = CType(sender, DropDownList)
        Dim pageNo As Integer = Convert.ToInt32(PageJumpDDL.SelectedValue)
 
        Dim startRowIndex As Integer = (pageNo - 1) * ProductListPager.PageSize
 
        ProductListPager.SetPageProperties(startRowIndex, ProductListPager.PageSize, True)
 
    End Sub
Start your free trial to view this solution
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Question Stats
Zone: Programming
Question Asked By: goherceg
Solution Provided By: TheLearnedOne
Participating Experts: 1
Solution Grade: B
Views: 0
Translate:
Loading Advertisement...
 
[+][-]Expert Comment by TheLearnedOne

Rank: Genius

Expert Comment by TheLearnedOne:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by goherceg
Author Comment by goherceg:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by TheLearnedOne

Rank: Genius

Expert Comment by TheLearnedOne:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by goherceg
Author Comment by goherceg:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Accepted Solution by TheLearnedOne

Rank: Genius

Accepted Solution by TheLearnedOne:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by goherceg
Author Comment by goherceg:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by TheLearnedOne

Rank: Genius

Expert Comment by TheLearnedOne:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by goherceg
Author Comment by goherceg:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by TheLearnedOne

Rank: Genius

Expert Comment by TheLearnedOne:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080723-EE-VQP-34 / EE_QW_2_20070628