Advertisement

02.23.2008 at 05:03PM PST, ID: 23187825
[x]
Attachment Details

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

Asked by goherceg in .NET Framework 3.x versions, Programming for ASP.NET

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 DropDovnListStart Free Trial
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
[+][-]02.25.2008 at 06:46AM PST, ID: 20975734

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.25.2008 at 10:25AM PST, ID: 20977892

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.25.2008 at 10:35AM PST, ID: 20977969

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.25.2008 at 10:46AM PST, ID: 20978067

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.25.2008 at 11:13AM PST, ID: 20978294

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: .NET Framework 3.x versions, Programming for ASP.NET
Tags: asp.net
Sign Up Now!
Solution Provided By: TheLearnedOne
Participating Experts: 1
Solution Grade: B
 
 
[+][-]02.25.2008 at 11:57AM PST, ID: 20978643

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.25.2008 at 12:41PM PST, ID: 20979015

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.25.2008 at 12:55PM PST, ID: 20979141

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.25.2008 at 02:02PM PST, ID: 20979703

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628