Paging using repeater control

Discussion in 'ASP .Net' started by Eugene Anthony, Feb 9, 2007.

  1. The problem with my coding is that despite removing the records stored
    in the array list, the rptPages repeater control is till visible. The
    rptPages repeater control displayes the navigation link (1,2,3 so on).
    The code is as bellow:



    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.ConnectionStrings["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();
    }
    }


    How do I solve the problem?.


    Regards


    Eugene Anthony

    *** Sent via Developersdex http://www.developersdex.com ***
     
    Eugene Anthony, Feb 9, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    3,701
    john_teague
    Sep 1, 2005
  2. Eugene Anthony

    Paging using repeater control

    Eugene Anthony, Feb 9, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    388
    Eugene Anthony
    Feb 9, 2007
  3. darrel
    Replies:
    1
    Views:
    299
    Teemu Keiski
    Mar 6, 2004
  4. bill

    paging with repeater control

    bill, Mar 21, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    103
  5. aspnetdir

    paging using repeater control

    aspnetdir, Apr 30, 2006, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    209
    Teemu Keiski
    Apr 30, 2006
Loading...

Share This Page