How Dynamic data Filtering works with autofills?

Oct 9, 2008 at 1:08 PM
How Dynamic data filtering works when you add new items, passing DynamicFilterControls from DynamicFilterForm
 or DynamicFilterRepeater ?

Please see background infomation from http://www.codeverge.net/item.aspx?item=449326 first.

Thanks,
Kallen


 

Oct 13, 2008 at 1:53 PM
I'm not quite sure what you are asking?  How are you adding new items?  Could you post complete code examples?
Oct 13, 2008 at 5:59 PM

What I really wanted is pass search key & value using DynamicFilterRepeater when insert new items. see code below

in List.aspx  I've replaced FilterRepeater to DynamicFilterRepeater. And Added OnClick="Button1_Click" to insert new button.

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

<%@ Register Assembly="Catalyst.Web.DynamicData" Namespace="Catalyst.Web.DynamicData"
    TagPrefix="asp" %>

<%@ 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>testing suppliers page <%= 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="GridViewValidator" ControlToValidate="GridView1" Display="None" />
           
           
<%--            <asp:FilterRepeater ID="FilterRepeater" runat="server">
                <ItemTemplate>
                    <asp:Label runat="server" Text='<%# Eval("DisplayName") %>' AssociatedControlID="DynamicFilter$DropDownList1" />
                    <asp:DynamicFilter runat="server" ID="DynamicFilter" OnSelectedIndexChanged="OnFilterSelectedIndexChanged" />
                </ItemTemplate>
                <FooterTemplate><br /><br /></FooterTemplate>
            </asp:FilterRepeater>--%>
           
            <asp:DynamicFilterRepeater ID="DynamicFilterRepeater" 
                    DataSourceID = "GridDataSource" runat="server">
                <HeaderTemplate>
                    <div>
                        Search</div>
                </HeaderTemplate>
                <ItemTemplate>
                    <div>
                        <asp:Label ID="Label1" runat="server" Text='<%# Eval("DisplayName") %>' ></asp:Label>
                        <asp:DynamicFilterControl
                                ID="DynamicFilter" runat="server">
                        </asp:DynamicFilterControl>
                    </div>
                </ItemTemplate>
                <FooterTemplate>
                    <div>
                        <asp:LinkButton ID="SearchButton" runat="server" CommandName="Search" Text="Search">
                        </asp:LinkButton> <br />
                        <asp:LinkButton ID="ClearButton" runat="server" CommandName="Clear"
                            Text="Clear">
                        </asp:LinkButton>
                        </div>
                </FooterTemplate>
            </asp:DynamicFilterRepeater>

            <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:DynamicLinqDataSource ID="GridDataSource"
                ContextTypeName="testDataContext"
                 EnableDelete="true"
                 EnableUpdate="true"
                runat="server" >
            </asp:DynamicLinqDataSource>
            <br />

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



And in List.aspx.cs

    protected void Button1_Click(object sender, EventArgs e) {       
        RouteValueDictionary rd = new RouteValueDictionary();
        foreach (Control c in FilterRepeater.Controls)    ------------- using DynamicFilterRepeater here?
        {
            foreach (Control d in c.Controls) {
                if (d is FilterUserControlBase)   ----------------------- ??
                {
                    FilterUserControlBase fub = (FilterUserControlBase)d;
                    string key = fub.DataField;
                    string value = fub.SelectedValue;
                   rd.Add(key, value);
                }
           }
       }
       string url = table.GetActionPath(PageAction.Insert, rd);
       Response.Redirect(url);
   }

And in Insert.aspx.cs, added following

    protected void DetailsView1_DataBound(object sender, EventArgs e)
    {
        foreach (MetaColumn column in table.Columns)
        {
            string value = Request.QueryString[column.Name];
            if (!string.IsNullOrEmpty(value))
            {
                var ftuc = DetailsView1.FindFieldTemplate(column.Name) as FieldTemplateUserControl;
                if (ftuc.DataControl is DropDownList)
                {
                    var ddl = ftuc.DataControl as DropDownList;
                    ListItem item = ddl.Items.FindByValue(value);
                    if (item != null)
                    {
                        item.Selected = true;
                    }
                }
                else if (ftuc.DataControl is CheckBox)
                {
                    var cb = ftuc.DataControl as CheckBox;
                    cb.Checked = string.Compare(value, "true", true) == 0;
                }
            }
        }

    }






Oct 13, 2008 at 8:49 PM
Ah, I see what you are trying to do.  You are trying to pre-populate the inert form controls based on the values in the search criteria on the lists page.  Interesting... I'll try to test this out when I get a minute today.
Oct 13, 2008 at 10:37 PM
Thanks Josh. 
That's right. I wanted pre-populate the insert form controls based on the values in the search criteria (e.g. FilterMode = FilterControlMode.Equals) on the lists page.