473,395 Members | 1,488 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,395 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 2525

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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.