locked
how to set FilterRepeater's ContextTypeName & TableName property. RRS feed

  • Question

  • User1174340047 posted

    hi.all

    I am developing a custom page template for the Orders table of Northwind.

    1. copy the Details.aspx and Details.aspx.cs to the newly created folder "Orders" under "CustomPages".

    2. copy all the content of the <ContentTemplate>  element in the List.aspx to the CustomPages\Orders\Details.aspx

    3. because i want the custom Details.aspx page not only display the selected Orders row, i also want the page to display the corresponding Order Details rows, so i override the FilterRepeater's default route setting by setting ContextTypeName="DataClassesDataContext" TableName="Order_Details" .

    when the page is loaded,  the following exception occurs:

    The table 'Orders' does not have a column named 'Order'.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.InvalidOperationException: The table 'Orders' does not have a column named 'Order'.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:

    [InvalidOperationException: The table 'Orders' does not have a column named 'Order'.]
       System.Web.DynamicData.MetaTable.GetColumn(String columnName) +145657
       System.Web.DynamicData.DynamicControlParameter.GetWhereParameters(IDynamicDataSource dataSource) +182
       System.Web.DynamicData.DynamicDataExtensions.ExpandWhereParameter(IDynamicDataSource dataSource, Parameter parameter) +80
       System.Web.DynamicData.DynamicDataExtensions.ExpandWhereParameter(IDynamicDataSource dataSource, Parameter parameter) +122
       System.Web.DynamicData.DynamicDataExtensions.ExpandDynamicWhereParameters(IDynamicDataSource dataSource) +287
       System.Web.DynamicData.DynamicDataManager.OnLoad(EventArgs e) +128
       System.Web.UI.Control.LoadRecursive() +50
       System.Web.UI.Control.LoadRecursive() +141
       System.Web.UI.Control.LoadRecursive() +141
       System.Web.UI.Control.LoadRecursive() +141
       System.Web.UI.Control.LoadRecursive() +141
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
    

    Here is the custom Details.aspx:

    <%@ Page Language="C#" MasterPageFile="~/Site.master" CodeFile="Details.aspx.cs" Inherits="Details" %>

    <%@ Register src="~/DynamicData/Content/GridViewPager.ascx" tagname="GridViewPager" tagprefix="asp" %>
    <%@ Register src="~/DynamicData/Content/FilterUserControl.ascx" tagname="DynamicFilter" tagprefix="asp" %>

    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
        <asp:DynamicDataManager ID="DynamicDataManager1" runat="server" AutoLoadForeignKeys="true" />

        <h2>Entry from table <%= table.DisplayName %></h2>

        <asp:ScriptManagerProxy runat="server" ID="ScriptManagerProxy1" />

        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:ValidationSummary ID="ValidationSummary1" runat="server" EnableClientScript="true"
                    HeaderText="List of validation errors" />
                <asp:DynamicValidator runat="server" ID="DetailsViewValidator" ControlToValidate="DetailsView1" Display="None" />

                <asp:DetailsView ID="DetailsView1" runat="server" DataSourceID="DetailsDataSource" OnItemDeleted="DetailsView1_ItemDeleted"
                    CssClass="detailstable" FieldHeaderStyle-CssClass="bold" >
                    <Fields>
                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:HyperLink ID="EditHyperLink" runat="server"
                                    NavigateUrl='<%# table.GetActionPath(PageAction.Edit, GetDataItem()) %>'
                                    Text="Edit" />
                                <asp:LinkButton ID="DeleteLinkButton" runat="server" CommandName="Delete" CausesValidation="false"
                                    OnClientClick='return confirm("Are you sure you want to delete this item?");'
                                    Text="Delete" />
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Fields>
                </asp:DetailsView>

                <asp:LinqDataSource ID="DetailsDataSource" runat="server" EnableDelete="true">
                    <WhereParameters>
                        <asp:DynamicQueryStringParameter />
                    </WhereParameters>
                </asp:LinqDataSource>

                <br />

                <div class="bottomhyperlink">
                    <asp:HyperLink ID="ListHyperLink" runat="server">Show all items</asp:HyperLink>
                </div>
               
                <br />
                <br />
                <br />
               
                <asp:ValidationSummary ID="ValidationSummary2" runat="server" EnableClientScript="true"
                    HeaderText="List of validation errors" />
                <asp:DynamicValidator runat="server" ID="GridViewValidator" ControlToValidate="GridView1" Display="None" />

                <asp:FilterRepeater ID="FilterRepeater" runat="server" ContextTypeName="DataClassesDataContext" TableName="Order_Details" >
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Eval("DisplayName") %>' AssociatedControlID="DynamicFilter$DropDownList1" />
                        <asp:DynamicFilter runat="server" ID="DynamicFilter" OnSelectedIndexChanged="OnFilterSelectedIndexChanged" />
                       
                    </ItemTemplate>
                    <FooterTemplate><br /><br /></FooterTemplate>
                </asp:FilterRepeater>

                <asp:GridView ID="GridView1" runat="server" DataSourceID="GridDataSource"
                    AllowPaging="True" AllowSorting="True" CssClass="gridview">
                    <Columns>
                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:HyperLink ID="EditHyperLink" runat="server"
                                    NavigateUrl='<%# table.GetActionPath(PageAction.Edit, GetDataItem()) %>'
                                Text="Edit" />&nbsp;<asp:LinkButton ID="DeleteLinkButton" runat="server" CommandName="Delete"
                                    CausesValidation="false" Text="Delete"
                                    OnClientClick='return confirm("Are you sure you want to delete this item?");'
                                />&nbsp;<asp:HyperLink ID="DetailsHyperLink" runat="server"
                                    NavigateUrl='<%# table.GetActionPath(PageAction.Details, GetDataItem()) %>'
                                    Text="Details" />
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>

                    <PagerStyle CssClass="footer"/>       
                    <PagerTemplate>
                        <asp:GridViewPager runat="server" />
                    </PagerTemplate>
                    <EmptyDataTemplate>
                        There are currently no items in this table.
                    </EmptyDataTemplate>
                </asp:GridView>


                <asp:LinqDataSource ID="GridDataSource" runat="server" EnableDelete="true">
                    <WhereParameters>
                        <asp:DynamicControlParameter ControlID="FilterRepeater" />
                    </WhereParameters>
                </asp:LinqDataSource>
                <br />

                <div class="bottomhyperlink">
                    <asp:HyperLink ID="InsertHyperLink" runat="server"><img id="Img1" runat="server" src="~/DynamicData/Content/Images/plus.gif" alt="Insert new item" />Insert new item</asp:HyperLink>
                </div>                  
            </ContentTemplate>
        </asp:UpdatePanel>
    </asp:Content>

    Any hint or suggestion is highly appreciated. thank you.

    Wednesday, September 17, 2008 9:41 AM

Answers

  • User-330204900 posted

    I've tried the links from my pc and all is fine so here is the link http://csharpbits.notaclue.net/2008/07/part-4-detailsview-and-gridview-with.html to part 4 just copy and paste into your browser.

    Hope this helps [:D]

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 17, 2008 11:25 AM
  • User1641955678 posted

    Yes, it could be a network issue.  Looking at your original page, the problem is likely that you are not setting the context and table on the GridDataSource, so it ends up using Details, while you want Order_Details.  Try setting the ContextTypeName and TableName properties on it.

    David

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 18, 2008 1:18 AM

All replies

  • User-330204900 posted

    Hy My Crsytal, have a look at my series of article on that:

    1. Custom Pages Part 1 - Standard Custom Page based on an existing PageTemplate and customised in the DynamicData\CustomPages folder.
    2. Custom Pages Part 2 - A completely Custom Page again in the DynamicData\CustomPages folder.
    3. Custom Pages Part 3 - Standard ASP.Net Page with Dynamic Data features added to take advantage of the FieldTemplates.
    4. Custom Pages Part 4 - A DetailsView and a GridView using Validation Groups
    5. Custom Pages Part 5 - I18N? Internationalisation Custom Page 

    and in particular Custom Pages Part 4 which I think does just what you want.

    Hope this helps [:D]

    Wednesday, September 17, 2008 10:07 AM
  • User1174340047 posted

    hi,sjnaughton

    Thank you for your reply. but the hyperlinks you provide can not be displayed.

    Wednesday, September 17, 2008 11:01 AM
  • User-330204900 posted

    I've tried the links from my pc and all is fine so here is the link http://csharpbits.notaclue.net/2008/07/part-4-detailsview-and-gridview-with.html to part 4 just copy and paste into your browser.

    Hope this helps [:D]

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 17, 2008 11:25 AM
  • User1174340047 posted

    But my browser can not display it.

    Can you send it to callyuhuanquan@live.com

    Thank you so much.

    Wednesday, September 17, 2008 8:43 PM
  • User1641955678 posted

    Steve's links work fine for me.  What do you mean when you say your browser can't display it?  Are you getting an error?

    David

    Wednesday, September 17, 2008 9:29 PM
  • User1174340047 posted

    hi, David

    I believe that the links work for you. But it doesn't work for me, either at home yesterday or at office today.

    the browser said the page cann't be displayed and it is because of request timeout. I am in China, maybe it is network problem.

    Does these articles are referenced by other website? I google them but can't find any.

    Thanks for your help.

    Wednesday, September 17, 2008 11:29 PM
  • User1641955678 posted

    Yes, it could be a network issue.  Looking at your original page, the problem is likely that you are not setting the context and table on the GridDataSource, so it ends up using Details, while you want Order_Details.  Try setting the ContextTypeName and TableName properties on it.

    David

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 18, 2008 1:18 AM
  • User1174340047 posted

    hi, David.

    Your suggestion works. I change

                <asp:LinqDataSource ID="GridDataSource" runat="server" EnableDelete="true">
                    <WhereParameters>
                        <asp:DynamicControlParameter ControlID="FilterRepeater" />
                    </WhereParameters>
                </asp:LinqDataSource>

    to

                <asp:LinqDataSource ID="GridDataSource" runat="server" EnableDelete="true" ContextTypeName="DataClassesDataContext" TableName="Order_Details">
                    <WhereParameters>
                        <asp:DynamicControlParameter ControlID="FilterRepeater" />
                    </WhereParameters>
                </asp:LinqDataSource>

     My requriement is achieved.

    You really give a terrific solution. Thank you so much. I believe that truely understanding is much more than a thousand how-tos. But for me, this is just another how-to because i don't understand how and why it works.

    I really want to find some document or articles that explain how dynamic data works.

     

    Thursday, September 18, 2008 1:41 AM