473,225 Members | 1,259 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,225 software developers and data experts.

Paging using repeater control

The problem with my coding is that despite removing the records stored
in the array list, the rptPages repeater
control is still visible. The rptPages repeater control displayes the
navigation link (1,2,3 so on). The code can be found in
SubscriptionCart.aspx.cs.

Default.aspx
------------

<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" 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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">

<table border="1" width="239" bordercolor="#FF0000" style="position:
relative">
<tr>
<td width="235">
<table border="0" width="232">
<tr>
<td width="93"><asp:Label ID="Label1" runat="server"
Font-Size="Small" ForeColor="Black" Text="subscription"
Width="49px"></asp:Label></td>
<td width="123"><asp:Label ID="Label2" runat="server"
Font-Size="Small" ForeColor="Black" Text="Label"
Width="46px"></asp:Label></td>
</tr>
<tr>
<td width="93"><asp:HyperLink ID="HyperLink1" runat="server"
Font-Size="Small"
NavigateUrl="SubscriptionCart.aspx">checkout</asp:HyperLink></td>
<td width="123"></td>
</tr>
</table>
</td>
</tr>
</table>
<br /><br />
&nbsp;<asp:Button ID="Button1" runat="server"
OnClick="Button1_Click" Style="left: 0px;
position: relative; top: -27px" Text="Button" />
<asp:HyperLink ID="HyperLink3" runat="server" Style="left:
-129px; position: relative;
top: 78px">1</asp:HyperLink>
<asp:HyperLink ID="HyperLink2" runat="server"
NavigateUrl="SubscriptionCart.aspx?GroupID=1"
Style="left: -74px; position: relative; top:
23px">First</asp:HyperLink>
<asp:HyperLink ID="HyperLink4" runat="server"
NavigateUrl="SubscriptionCart.aspx?GroupID=2"
Style="left: -105px; position: relative; top:
55px">Two</asp:HyperLink>
</form>
</body>
</html>
Default.aspx.cs
---------------

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
int numSubscription;
numSubscription = ((ArrayList)this.Session["Address"]).Count;
Label2.Text = numSubscription.ToString();

if (numSubscription == 0)
{
HyperLink1.Enabled = false;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("SubscriptionCart.aspx");
}
}
SubscriptionCart.aspx
---------------------

<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="SubscriptionCart.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">

<table border="1" width="239" bordercolor="#FF0000" style="position:
relative">
<tr>
<td width="235">
<table border="0" width="232">
<tr>
<td width="93"><asp:Label ID="Label3" runat="server"
Font-Size="Small" ForeColor="Black" Text="subscription"
Width="49px"></asp:Label></td>
<td width="123"><asp:Label ID="Label2" runat="server"
Font-Size="Small" ForeColor="Black" Text="Label"
Width="46px"></asp:Label></td>
</tr>
<tr>
<td width="93"><asp:HyperLink ID="HyperLink1" runat="server"
Font-Size="Small"
NavigateUrl="SubscriptionCart.aspx">checkout</asp:HyperLink></td>
<td width="123"></td>
</tr>
</table>
</td>
</tr>
</table>
<br /><br />

<asp:Repeater ID="rptItems" runat="server"
OnItemCommand="rptItems_ItemCommand">
<HeaderTemplate>
<table>
<tr>
<td bgcolor="#FFCC99">GroupID</td><td
bgcolor="#FFCC99">MemberID</td><td bgcolor="#FFCC99"></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# Eval("GroupID") %></td><td><%# Eval("MemberID")
%></td><td><asp:LinkButton ID="LinkButton2"
runat="server">Remove</asp:LinkButton></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
&nbsp;
<br />
<asp:Repeater ID="rptPages" Runat="server">
<HeaderTemplate>
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td><b>Page:</b>&nbsp;</td>
<td>
</HeaderTemplate>
<ItemTemplate>
<asp:LinkButton ID="btnPage"
CommandName="Page"
CommandArgument="<%#
Container.DataItem %>"
CssClass="text"
Runat="server"><%# Container.DataItem %>
</asp:LinkButton>&nbsp;
</ItemTemplate>
<FooterTemplate>
</td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>
<br /><br />

<table border="0" width="309">
<tr>
<td style="width: 144px; height: 21px;"><asp:HyperLink
ID="HyperLink4" runat="server" NavigateUrl="Default.aspx">return to
subscription</asp:HyperLink></td>
<td style="width: 166px; height: 21px;"><asp:LinkButton
ID="LinkButton1" runat="server"
OnClick="LinkButton1_Click">Confirm</asp:LinkButton></td>
</tr>
</table>

</form>
</body>
</html>


SubscriptionCart.aspx.cs
------------------------

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Data.SqlClient;
using MyProject;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
BindData();
UpdateSubCounter();
}

public int PageNumber
{
get
{
if (ViewState["PageNumber"] != null)
return Convert.ToInt32(ViewState["PageNumber"]);
else
return 0;
}
set
{
ViewState["PageNumber"] = value;
}
}

protected override void OnInit(EventArgs e)
{
base.OnInit(e);
rptPages.ItemCommand +=
new RepeaterCommandEventHandler(rptPages_ItemCommand);
}

public void BindData()
{
String GroupID = Request.QueryString["GroupID"];

if (GroupID != null)
{
Subscription sub = new Subscription();
sub.groupid = int.Parse(GroupID.ToString()); //1;
sub.memberid = 2;

if (((ArrayList)this.Session["Address"]).Contains(sub) ==
false)
{
((ArrayList)this.Session["Address"]).Add(sub);
LoadData();
}
else
{
LoadData();
}
}
else
{
LoadData();
}
}

public void LoadData()
{
PagedDataSource pgitems = new PagedDataSource();
pgitems.DataSource = ((ArrayList)this.Session["Address"]);
pgitems.AllowPaging = true;
pgitems.PageSize = 1;
pgitems.CurrentPageIndex = PageNumber;

if (pgitems.PageCount 1)
{
rptPages.Visible = true;
ArrayList pages = new ArrayList();
for (int i = 0; i < pgitems.PageCount; i++)
pages.Add((i + 1)).ToString();
rptPages.DataSource = pages;
rptPages.DataBind();
}
else
{
rptPages.Visible = true;
}

rptItems.DataSource = pgitems;
rptItems.DataBind();
}

public void UpdateSubCounter()
{
int numSubscription;
numSubscription = ((ArrayList)this.Session["Address"]).Count;
Label2.Text = numSubscription.ToString();

if (numSubscription == 0)
{
HyperLink1.Enabled = false;
LinkButton1.Enabled = false;
}
}

protected void LinkButton1_Click(object sender, EventArgs e)
{
for (int rowindex = 0; rowindex <
((ArrayList)this.Session["Address"]).Count; rowindex++)
{
Subscription m =
(Subscription)((ArrayList)this.Session["Address"])[rowindex];
SqlConnection cnn = new
SqlConnection(ConfigurationManager.ConnectionStrin gs["myConnection"].Con
nectionString);
SqlCommand myCommand = new SqlCommand();
myCommand.Connection = cnn;
myCommand.CommandText = "INSERT subscription VALUES(" +
m.groupid + "," + m.memberid + ")";
SqlDataAdapter myAdapter = new SqlDataAdapter(myCommand);
DataSet ds = new DataSet();
myAdapter.Fill(ds, "subscription");
}

Response.Redirect("SubscriptionListing.aspx");
}
protected void rptItems_ItemCommand(object source,
RepeaterCommandEventArgs e)
{
LinkButton m = (LinkButton)e.Item.FindControl("LinkButton2");
int rowindex = m.TabIndex;

((ArrayList)this.Session["Address"]).Remove(((ArrayList)this.Session["Ad
dress"])[rowindex]);
LoadData();
UpdateSubCounter();
}

protected void rptPages_ItemCommand(object source,
RepeaterCommandEventArgs e)
{
PageNumber = Convert.ToInt32(e.CommandArgument) - 1;
LoadData();
}
}
Subscription.cs
---------------
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for subscription
/// </summary>

namespace MyProject
{
public class Subscription
{
int _groupid, _memberid;

public int groupid
{
get { return _groupid; }
set { _groupid = value; }
}

public int memberid
{
get { return _memberid; }
set { _memberid = value; }
}

public override bool Equals(Object o)
{
Subscription s = (Subscription)o;
return (s.groupid == this.groupid && s.memberid ==
this.memberid);
}
}
}
How do I solve the problem?.
Your help is kindly appreciated.

Eugene Anthony

*** Sent via Developersdex http://www.developersdex.com ***
Feb 9 '07 #1
0 2509

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mark | last post by:
I am attempting to build a repeating list using a repeater control. I want to add a checkbox to each item (line) and 'Select All' and 'Clear All' buttons. I have figured out how to do this...
1
by: Guadala Harry | last post by:
I understand that paging is a built-in feature of the DataGrid, and that paging is not built-in to other listing controls such as the DataList and the Repeater. I need to implement paging...
2
by: Steven K | last post by:
Hello, I am converting an ASP page to ASP.Net. In one page, I am using record paging. I have read that while the DataGrid control has paging, it can tax resources. So I did a Google and found...
1
by: Dan Nash | last post by:
Hi guys Just developing a cool list that pulls data from an SQL database. I've got a nice header, a footer, borders down the side, but no top/bottom borders for the rows, and onmouseover /...
8
by: Matthew Curiale | last post by:
I am creating an app that lists clients of a company for management of different attributes for that company. The first page is a listing of the companies currently in the database. I have my...
1
by: ratnakarp | last post by:
Hi, I have a search text box. The user enters the value in the text box and click on enter button. In code behind on button click i'm writing the code to get the values from the database and...
0
by: csockwell | last post by:
I love the objectdatasource conrtol but I'm having trouble using the paging controls. I'm trying to create a user control to which I can bind a objectdatasource control. I've been successful at...
0
by: csockwell | last post by:
I'm having trouble using the paging controls. I'm trying to create a user control to which I can bind a objectdatasource control. I've been successful at binding to a repeater and I would like...
2
by: Jeff | last post by:
Hey ASP.NET 2.0 GridView have AllowPaging & PageSize for the letting the GridView span multiple pages. But is the same allowed on a Repeater control? I didn't see any properties like...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.