hai,

I used gridview pager for page sizing. But I have more than 15 web pages that are also needed page sizing. how can i create a class for this purpose and access it.

The code I used is:

protected void GrdStudent_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Pager)
        {
            DropDownList ddl = new DropDownList();
            //adds variants of pager size
            ddl.Items.Add("5");
            ddl.Items.Add("10");
            ddl.Items.Add("15");
            ddl.AutoPostBack = true;
            //selects item due to the GridView current page size
            ListItem li = ddl.Items.FindByText(GrdStudent.PageSize.ToString());
            if (li != null)
                ddl.SelectedIndex = ddl.Items.IndexOf(li);
            ddl.SelectedIndexChanged += new EventHandler(ddl_SelectedIndexChanged);

            //adds dropdownlist in the additional cell to the pager table
            Table pagerTable = e.Row.Cells[0].Controls[0] as Table;
            TableCell cell = new TableCell();
            cell.Style["padding-left"] = "15px";
            cell.Controls.Add(new LiteralControl("Page Size:"));
            cell.Controls.Add(ddl);
            pagerTable.Rows[0].Cells.Add(cell);
        }
    }
void ddl_SelectedIndexChanged(object sender, EventArgs e)
    {
        //changes page size
        GrdStudent.PageSize = int.Parse(((DropDownList)sender).SelectedValue);
        //binds data source
        DataTable ObjDt = ViewState["table"] as DataTable;
        GrdStudent.DataSource = ObjDt;
        GrdStudent.DataBind();
    }

Thanks in advance,

sreevidya.

hi bro,
can u explain more about your problem,
any way try this:

private void LoadData(int [U][B]PageSize[/B][/U])
        {
            DataTable dt = new DataTable();
            dt= "your query to DataBase "
            PagedDataSource pgitems = new PagedDataSource();
            DataView dv = new DataView(dt);
            pgitems.DataSource = dv;
            pgitems.AllowPaging = true;
            [U][B]pgitems.PageSize = PageSize[/B][/U];
            pgitems.CurrentPageIndex = PageNumber;
            GrdStudent.DataSource = pgitems;        
            GrdStudent.DataBind();
        }

hope helps u

hai,
thank you for your replay.

but my problem is that the two events I described can call from a class to the aspx pages taht includes gridview. I could call the first event but couldnt second.

I did it like follows:
Class:

public  class GetGridEvent
{
	public GetGridEvent()
	{
		//
		// TODO: Add constructor logic here
		//
	}
   
                   
    public void GridRowCreatedEventHandler(Object src,GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Pager)
        {
            DropDownList ddl = new DropDownList();
            //adds variants of pager size
            ddl.Items.Add("5");
            ddl.Items.Add("10");
            ddl.Items.Add("15");
            ddl.AutoPostBack = true;
            Table pagerTable = e.Row.Cells[0].Controls[0] as Table;
            TableCell cell = new TableCell();
            cell.Style["padding-left"] = "15px";
            cell.Controls.Add(new LiteralControl("Page Size:"));
            cell.Controls.Add(ddl);
            pagerTable.Rows[0].Cells.Add(cell);
            ddl.SelectedIndexChanged += new EventHandler(ddl_SelectedIndexChanged);

        }
    }

calling event at aspx page:

GetGridEvent grdEvnt = new GetGridEvent();         GrdStudentMarkList.RowCreated += new GridViewRowEventHandler(grdEvnt.GridRowCreatedEventHandler);

Like taht how can i manage the dropdown list selectedIndexChage evnet.

You can use Pagesize property and set that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.