Posts asp.net - linq - listview - datapager
Post
Cancel

asp.net - linq - listview - datapager

source - https://dzone.com/articles/paging-listview-using

The problem is upon clicking the next button for the first time nothing happens.But if the next button is clicked second time, then only the second page appears.

Add PagePropertiesChanging event on Listview control.

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
//http://forums.asp.net/t/1260300.aspx

	List<customers> activeCustomers = null;

	protected void Page_Init(object sender, EventArgs e)
	{

		using (CustomersContext context = new CustomersContext(General.ConnectionString))
		{
			// get sections 
			activeCustomers = sections.Where(i => i.IsActive).ToList();
		}

	}

	protected void Page_Load(object sender, EventArgs e)
	{
		if (!IsPostBack)
		{
			BindListView();
		}
	}

<asp:listview runat="server" id="lstv" onpagepropertieschanging="lstv_PagePropertiesChanging" onitemdatabound="lstv_ItemDataBound" itemplaceholderid="PlaceHolder1">
	<layouttemplate>
		<asp:placeholder id="PlaceHolder1" runat="server"></asp:placeholder>
	</layouttemplate>
	<itemtemplate>
		<div class="one_fourth">
			<asp:hyperlink id="hlnkClientImage" runat="server">
				<asp:image id="imgClientImage" cssclass="cirimg" runat="server"></asp:image>
			</asp:hyperlink>
			<div class="cinfo">

##### 
					<asp:literal id="ltrlClientTitle" runat="server"></asp:literal>

				 *<asp:literal id="ltrlClientDesc" runat="server"></asp:literal>*

				<asp:hyperlink id="lnkViewBio" cssclass="button1 button blue" runat="server"></asp:hyperlink>
			</div>
		</div>
	</itemtemplate>
</asp:listview>
<div>
	<div class="pagination center">
		<% var test = SiteSession.LanguageId == 1 ? "Προηγούμενο" : "Επόμενο"; %>
		<asp:datapager runat="server" id="ProductsDataPager" pagesize="12" pagedcontrolid="lstv">
			<fields>
				<asp:nextpreviouspagerfield showfirstpagebutton="true" firstpagetext="START" shownextpagebutton="False" previouspagetext="< Previous" buttoncssclass="navlinks"></asp:nextpreviouspagerfield>
				<asp:numericpagerfield buttontype="Link" currentpagelabelcssclass="navlinks active" numericbuttoncssclass="navlinks notactive" rendernonbreakingspacesbetweencontrols="True" visible="True"></asp:numericpagerfield>
				<asp:nextpreviouspagerfield showlastpagebutton="true" lastpageimageurl="END" showpreviouspagebutton="false" shownextpagebutton="true" nextpagetext="Next >" buttoncssclass="navlinks"></asp:nextpreviouspagerfield>
			</fields>
		</asp:datapager>
	</div>
</div>

protected void lstv_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
{
	this.ProductsDataPager.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);

	// Rebind the ListView1  
	BindListView(); 
}

public void BindListView()
{
	lstv.DataSource = activeCustomers;
	lstv.DataBind();
}

ASP:DataPager control settings to work perfectly w/ the Bootstrap single button group

js //https://gist.github.com/cceremuga/5204350 <asp:datapager id="DataPagerProducts" runat="server" pagedcontrolid="LvCategoryItems" pagesize="10" onprerender="PagerCategoryItems_PreRender" class="btn-group pager-buttons"> <fields> <asp:nextpreviouspagerfield showlastpagebutton="False" shownextpagebutton="False" buttontype="Button" buttoncssclass="btn" rendernonbreakingspacesbetweencontrols="false"></asp:nextpreviouspagerfield> <asp:numericpagerfield buttontype="Button" rendernonbreakingspacesbetweencontrols="false" numericbuttoncssclass="btn" currentpagelabelcssclass="btn disabled" nextpreviousbuttoncssclass="btn"></asp:numericpagerfield> <asp:nextpreviouspagerfield showfirstpagebutton="False" showpreviouspagebutton="False" buttontype="Button" buttoncssclass="btn" rendernonbreakingspacesbetweencontrols="false"></asp:nextpreviouspagerfield> </fields> </asp:datapager> </customers>

origin - http://www.pipiscrew.com/?p=3437 asp-net-linq-listview-datapager

This post is licensed under CC BY 4.0 by the author.
Contents

Trending Tags