locked
GridView Adapter with PagerTemplate broken RRS feed

  • Question

  • User1603243177 posted

    In using the CSS Control Adapters on a paged GridView, initially all worked correctly.  However, as soon as I added a PagerTemplate to the GridView markup, paging disappeared, never to return.  I tracked this down to the WritePagerSection() method in GridViewAdapter, which apparently only has logic to process the <table> tags that the ASP.NET GridView normally uses for the built-in paging markup. I confirmed this by building a PagerTemplate like this:

    <PagerTemplate><asp:Table ID="tmp" runat="server"><asp:TableRow runat="server"><asp:TableCell runat="server">
        <asp:LinkButton Tooltip="Previous Page" CommandName="Page" CommandArgument="Prev" runat="server" ID="btnPrevious" OnCommand="Paginate" >Previous</asp:LinkButton>
    </asp:TableCell></asp:TableRow></asp:Table></PagerTemplate>

    which correctly outputs the paging section (no spaces or returns may be between PagerTemplate and the table tags or the WritePagerSection() logic sees the them as a Literal and ignores the PagerTemplate, or more precisely the contents of the Top/BottomPagerRow).

    I'm not very familiar with the Template/ControlBuilder area of ASP.NET, but I think that by the time WritePagerSection() is called, Top/BottomPagerRow contains the parsed control array from PagerTemplate.  I implemented else logic in WritePagerSection() to simply iterate over the Controls collection from Top/BottomPagerRow and call RenderControl (wrapping it all with a <div> as the existing logic does).

    Is this a known issue? Is my simple solution of iterating over the controls array with RenderControl sufficient in all cases?

    Thanks, Shane 

    Wednesday, February 21, 2007 2:06 AM

All replies

  • User1568006047 posted

    I think I am slightly lost here, but certainly the CSS Control Adapters don't render my PagerTemplate within my GridView.

    I have had to comment out the gridview adaptor, which is a big shame[:(]:

      <!--<adapter controlType="System.Web.UI.WebControls.GridView" adapterType="CSSFriendly.GridViewAdapter" />-->

    Does anyone have a solution?

    Tuesday, March 6, 2007 9:07 AM
  • User1002205838 posted
    I'm having the same problem. I've yet to find a solution.
    Monday, April 16, 2007 12:57 PM
  • User1735976268 posted

    This same problem exists with the FormView control as well.

     

    A fix would be greatly appreciated! 

    Monday, April 16, 2007 4:31 PM
  • User374569943 posted

    The code below works but there's still a problem with skinned controls rendering properly (regular server controls render fine)

      

    private void WritePagerSection(HtmlTextWriter writer, PagerPosition pos)
    {
        GridView gridView = Control as GridView;
    
        if (gridView != null && 
            gridView.AllowPaging && 
            gridView.PageCount > 1 && 
            (gridView.PagerSettings.Position == pos || gridView.PagerSettings.Position == PagerPosition.TopAndBottom))
        {
            string className = "AspNet-GridView-Pagination AspNet-GridView-";
            className += (pos == PagerPosition.Top) ? "Top " : "Bottom ";
            if (gridView.PagerStyle != null)
            {
                className += gridView.PagerStyle.CssClass;
            }
            className = className.Trim();
    
            writer.WriteLine();
            writer.WriteBeginTag("div");
            writer.WriteAttribute("class", className);
            writer.Write(HtmlTextWriter.TagRightChar);
            writer.Indent++;
    
            if (gridView.PagerTemplate != null)
            {
                PlaceHolder container = new PlaceHolder();
                gridView.PagerTemplate.InstantiateIn(container);
                container.DataBind();
                container.RenderControl(writer);
            }
            else
            {
                Table innerTable = null;
                if ((pos == PagerPosition.Top) &&
                    (gridView.TopPagerRow != null) &&
                    (gridView.TopPagerRow.Cells.Count == 1) &&
                    (gridView.TopPagerRow.Cells[0].Controls.Count == 1) &&
                    typeof(Table).IsAssignableFrom(gridView.TopPagerRow.Cells[0].Controls[0].GetType()))
                {
                    innerTable = gridView.TopPagerRow.Cells[0].Controls[0] as Table;
                }
                else if ((pos == PagerPosition.Bottom) &&
                    (gridView.BottomPagerRow != null) &&
                    (gridView.BottomPagerRow.Cells.Count == 1) &&
                    (gridView.BottomPagerRow.Cells[0].Controls.Count == 1) &&
                    typeof(Table).IsAssignableFrom(gridView.BottomPagerRow.Cells[0].Controls[0].GetType()))
                {
                    innerTable = gridView.BottomPagerRow.Cells[0].Controls[0] as Table;
                }
    
                if ((innerTable != null) && (innerTable.Rows.Count == 1))
                {
                    TableRow row = innerTable.Rows[0];
                    foreach (TableCell cell in row.Cells)
                    {
                        foreach (Control ctrl in cell.Controls)
                        {
                            writer.WriteLine();
                            ctrl.RenderControl(writer);
                        }
                    }
                }                
            }
    
            writer.Indent--;
            writer.WriteLine();
            writer.WriteEndTag("div");
        }
    }
     
    Friday, May 18, 2007 4:13 PM
  • User1284094771 posted

    will this code also apply to the FormView template as well?

    Wednesday, May 23, 2007 1:26 AM
  • User1284094771 posted

    In Case anyone is wondering, I was at CodePlex for the DLL for the adapters and it looks like someone is addressing that the FormView didn't have all the paging options implemented but it's being worked on now. (that was a poorly constructed sentence)

     Stay Tuned.


    http://www.codeplex.com/cssfriendly/SourceControl/ListDownloadableCommits.aspx


    Friday, May 25, 2007 3:39 PM
  • User-1385398420 posted

    Changed 1588 has the full set of paging features for FormView and DetailsView.

    Note that a few pending changes to GridView are there, but there is not yet a test page in the WalkThru. If someone wants to draft up a test page (similar to the other WalkThru test pages) please feel free to and submit it as a patch.

     

    Friday, May 25, 2007 5:50 PM
  • User-265708580 posted

    None of the CSS Adapters seem to handle the Templates properly. Even the above suggested fix is limited to design-time markup. It appears that simply calling the .InstantiateIn method of the Template is not enough for it to render server controls modified at run-time properly. The EmptyDataTemplate for the GridView does seem to work because it uses a different technique which I don't see being able to apply to a PagerTemplate. The DetailsView and FormView EmptyDataTemplates also have this problem (as well as their PagerTemplates).

    Example (using DetailsView in WalkThru):

                    <EmptyDataTemplate>

                        <asp:PlaceHolder ID="phTest" runat="server" />

                    </EmptyDataTemplate>

     

    <!--EndFragment-->

        protected void DetailsViewSample_ItemCreated(object sender, EventArgs e)

        {

            ph = DetailsViewSample.FindControl("phTest") as PlaceHolder;

            if (ph != null)

            {

                Trace.Warn("Found empty data row.");

                ph.Controls.Add(new LiteralControl("testing"));

            }

        }

     

    This won't display anything with the CSS adapter enabled even though the trace hits normally. CSS Adapter disabled, the row will display the correct "testing" value. This can be a real problem when you want to implement a nice, dynamic PagerTemplate.

     

    I don't quite grok how templates work to suggest a solution, however.

    <!--EndFragment-->
    Thursday, July 26, 2007 11:54 AM
  • User-1065893324 posted

    Was this problem ever fixed? I am using CSSFriendly for the nice menu features and now im deep in the code and my custom paging template in GridView totally doesnt work with CSSFriendly. Seems odd that a year ago there were problems and they havent been addressed. Has this project been dropped?

    Thursday, October 9, 2008 5:18 AM
  • User-1385398420 posted

    You may want to test the latest version of the code from CodePlex (http://www.codeplex.com/cssfriendly). I know there have been pager-related check-ins, and they may have addressed your issues.

    Monday, October 13, 2008 9:33 AM