By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,978 Members | 1,389 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,978 IT Pros & Developers. It's quick & easy.

Paging using repeater control

P: n/a
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
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.