Click here to Skip to main content
16,021,417 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
I am binding gridview dynamically and when i try for paging I am not able to even see the paging on the page.My coding is as below.Please
suggest what I am misssing.I am binding Gridview in Page_Init event.paging is not showing at all with gridview.what could be the reason.I am using pageindexchanging event also but still I am not able
to see paging on the page.I am binding all times.I need the Gridview to be created dynamically so I am writing code behind

C++
workGrid.RowEditing += new GridViewEditEventHandler(workGrid_RowEditing);
  workGrid.RowDeleting += new GridViewDeleteEventHandler(workGrid_RowDeleting);
 workGrid.RowDataBound += new GridViewRowEventHandler(workGrid_RowDataBound);
  TemplateField BtnTmpField = new TemplateField();    BtnTmpField.ItemTemplate = new GridViewTemplate(ListItemType.Item, "Modify", "Command");
    BtnTmpField.HeaderTemplate = new GridViewTemplate(ListItemType.Header, "Modify", "Command");    BtnTmpField.EditItemTemplate = new GridViewTemplate(ListItemType.EditItem, "...", "Command");    workGrid.Columns.Clear();
  workGrid.Columns.Add(BtnTmpField);
 for (int workCnt = 0; workCnt < dtWorksGrid.Columns.Count; workCnt++)
 {        TemplateField ItemTmpField = new TemplateField();
     // create HeaderTemplate
ItemTmpField.HeaderTemplate = new GridViewTemplate(ListItemType.Header, dtWorksGrid.Columns[workCnt].ColumnName, dtWorksGrid.Columns[workCnt].DataType.Name);
     ItemTmpField.HeaderStyle.Width = Unit.Pixel(145);
     // create ItemTemplate
  ItemTmpField.ItemTemplate = new GridViewTemplate(ListItemType.Item, dtWorksGrid.Columns[workCnt].ColumnName, dtWorksGrid.Columns[workCnt].DataType.Name);
  //create EditItemTemplate
  ItemTmpField.EditItemTemplate = new GridViewTemplate(ListItemType.EditItem, dtWorksGrid.Columns[workCnt].ColumnName, dtWorksGrid.Columns[workCnt].DataType.Name);
     // then add to the GridView
   workGrid.Columns.Add(ItemTmpField);
 }


MIDL
workGrid.DataSource = dtWorksGrid;
  workGrid.DataBind();
 workGrid.AllowPaging = true;
workGrid.PageSize = 5;
  workGrid.PageIndexChanging += new GridViewPageEventHandler(workGrid_PageIndexChanging);


C#
void workGrid_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        bindWorkGrid(workType);
        reg_workgrid.PageIndex = e.NewPageIndex;
        reg_workgrid.DataBind();
    }
Posted
Updated 22-Mar-10 19:52pm
v3

1 solution

Are you binding every time, or are you using code to make sure it does not bind on postback ? Why are you setting all this in code instead of in the template ?

Page_Init is the wrong place to databind anyhow, prerender is the best place to do it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900