Search code examples
asp.net.netgridviewdynamic-data

Dynamic Data GridView Pager missing DynamicHyperlink Edit parameters


Edit: Feb 7, 2012 - Turns out the key parameter disappears from the GridView Edit link after a Sort as well, so it doesn't appear to be the Pager after all, but the problem persists... any ideas very welcome.

I have a Asp.Net Dynamic Data app. It uses the standard GridViewPager.aspx in Custom List.aspx which is marked up like this:

<asp:GridView ID="GridView1" runat="server" DataSourceID="GridDataSource" EnablePersistedSelection="True" CssClass="DDGridView" HeaderStyle-CssClass="th" RowStyle-CssClass="td" CellPadding="6" AllowSorting="True" AllowPaging="True" PageSize="3"
    OnRowDataBound="GridView_OnRowDataBound" OnRowDeleting="GridView_OnRowDeleting">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:LoginView ID="LoginView1" runat="server">
                    <RoleGroups>
                        <asp:RoleGroup Roles="admin">
                            <ContentTemplate>
                                <asp:DynamicHyperLink ID="EditLink" runat="server" Action="Edit" Text="edit" />
                                &nbsp;
                                <asp:LinkButton ID="LinkButton1" runat="server" CommandName="Delete" Text="delete" OnClientClick='return confirm("Are you sure you want to delete this item?");' />
                            </ContentTemplate>
                        </asp:RoleGroup>
                    </RoleGroups>
                </asp:LoginView>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
    <PagerStyle CssClass="DDFooter" />
    <PagerTemplate>
        <asp:GridViewPager runat="server" />
    </PagerTemplate>
    <EmptyDataTemplate>
        There are currently no items in this table.
    </EmptyDataTemplate>
</asp:GridView>

On page 1 of the List all is well. The Edit Link rendered includes ?key=xxxxx and the Edit form opens to the correct record.

Once we page off of Page 1 however, the Edit Link rendered on each row has no 'key' parameter and the Edit form always opens to the first row in the database.

I am at a loss to explain this or even where to look. There is no custom code attached to any event associated with the Edit DynamicHyperlink or the GridviewPager.

Has anyone experienced this or have any suggestions as to what might be the issue?


Solution

  • Found the answer here:

    LinkButton CommandArgument is empty when it is inside LoginView in a GridView

    Turns out good 'ol Microsoft forgot to wire LoginView to fire row-level databind events inside a GridView. No databind, no link parameters!

    In deference to a positive attitude, I'll make no comment on the level of organization it takes to allow that out the door....