Wednesday, August 19, 2015

How to fix the Pager Alginment issue in ASP.Net GridView

when i test my application test. I notice that the pager is not properly aligned in the page, as i try to add the new row to the grid.



when i use IE Deverlper Tool to debug the application, it showed that table column only has 1 which is supposed to span to 4 columns like this HTML Code <td colspan="4">

since the column span did not work in the pager row. we can manually change it in ItemCreated or RowCreated Event in the code behide.  we will check if the Pager row has only one cells, then we will expand the column with 4 cells.

protected void gridView_ItemCreated(object sender, DataGridItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Pager && e.Item.Cells.Count==1)
            {
                e.Item.Cells[0].Attributes.Add("colspan", "4");
            }
        }




No comments:

Post a Comment