[Mono-dev] GridView patches

Dumitru Ban dban at dako.ro
Thu Jun 28 03:46:34 EDT 2007


Hi,

I have 2 patches for the GridView. They are the result of trying to customize the pager of the GridView. I've created a CustomGridView derived from System.Web.UI.WebControls.GridView.
To customize the pager I'm using a pager template and override the InitializePager of the GridView:

protected override void InitializePager(GridViewRow row, int columnSpan, PagedDataSource pagedDataSource)
{
    if (this.ExtendedPager)
    {
        ExtendedPagerTemplate pagerTemplate = new ExtendedPagerTemplate(this.PageIndex, this.PageCount, this.PageSize, pagedDataSource.DataSourceCount, PagerStyle);
        base.PagerTemplate = pagerTemplate;
    }
    base.InitializePager(row, columnSpan, pagedDataSource);
}

Here is where the first problem appears. Because the GridView.PagerTemplare looks like this

public virtual ITemplate PagerTemplate {
    get { return pagerTemplate; }
    set { pagerTemplate = value; RequireBinding (); }
}

we will have infinte recursion. The RequireBinding() in the PagerTemplare should not be there. GridView_1.patch should fix this problem.

Also, I want the pager to be visible even if there is only one page. For this I override the CreateChildControls method of the GridView:

protected override int CreateChildControls(System.Collections.IEnumerable dataSource, bool dataBinding)
{
    int res = base.CreateChildControls(dataSource, dataBinding);
    if (PagerSettings.Visible == true)
    {
        if (PagerSettings.Position == PagerPosition.Bottom || PagerSettings.Position == PagerPosition.TopAndBottom)
            if (BottomPagerRow != null)
                BottomPagerRow.Visible = true;
        if (PagerSettings.Position == PagerPosition.Top || PagerSettings.Position == PagerPosition.TopAndBottom)
            if (TopPagerRow != null)
                TopPagerRow.Visible = true;
    }
    return res;
}

This works fine using Microsoft .NET. I've made some debugging and I saw that the pager is created even if there is only one page, but is not visible. The code written in the overridden CreateChildControls makes the pager to be visible. With MONO the pager is not created at all and the code written in the overridden CreateChildControls doesn't do anything because BottomPagerRow/TopPagerRow are null when only 1 page exists. GridView_2.patch should fix this problem. The patch also takes into account the value of PagerSetting.Visible for the pager creation.

Please review and apply them.

Thanks & best regards,
Dumi.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20070628/9ad47cb4/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: GridView_1.patch
Type: application/octet-stream
Size: 543 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20070628/9ad47cb4/attachment.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: GridView_2.patch
Type: application/octet-stream
Size: 2129 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20070628/9ad47cb4/attachment-0001.obj 


More information about the Mono-devel-list mailing list