CodeSmith Community
Your Code. Your Way. Faster!

GridView - FormView relationship

Latest post 02-21-2008 3:30 PM by IVX. 3 replies.
  • 02-01-2008 11:16 PM

    • velum
    • Top 25 Contributor
    • Joined on 07-14-2006
    • Montréal, Qc, Canada
    • Posts 188
    • Points 4,726

    GridView - FormView relationship

    Hi!

    I have a form containing a GridView and a FormView. When a row is selected in the GridView, I would like the details of that row to appear in the FormView. The key to retrieve the FormView data is based on two fields in the database. However, I cannot get this to work.

    Here is the GridView Data Source:

        <data:ImportMatchDetailsDataSource ID="dsImportMatchDetails"
            SelectMethod="GetPaged"
            EnablePaging="True"
            EnableSorting="True"
            EnableTransaction="False"
            runat="server">
            <Parameters>
                <data:SqlParameter Name="WhereClause" UseParameterizedFilters="false">
                    <Filters>
                        <data:ImportMatchDetailsExpressionBuilder Column="ImportDatabaseID" QueryStringField="ImportDatabaseID" BuilderExpression="AppendEquals" />
                        <data:ImportMatchDetailsExpressionBuilder Column="ClientNo" QueryStringField="ClientNo" BuilderExpression="AppendEquals" />
                        <data:ImportMatchDetailsExpressionBuilder Column="BonMatch" BuilderExpression="AppendIsNull" />
                    </Filters>
                </data:SqlParameter>
            </Parameters>
        </data:ImportMatchDetailsDataSource>

    And here is the FormView DataSource:

     
        <data:ImportMatchDetailsDataSource ID="dsSelectedImportMatchDetails"
            SelectMethod="GetPaged"
            EnablePaging="True"
            EnableSorting="True"
            EnableTransaction="False"
            runat="server">
            <Parameters>
                <data:SqlParameter Name="WhereClause" UseParameterizedFilters="false" ConvertEmptyStringToNull="true">
                    <Filters>
                        <data:ImportMatchDetailsFilter Column="ImportDatabaseID" QueryStringField="ImportDatabaseID" ComparisionType="Equals" DefaultValue="0" />
                        <data:ImportMatchDetailsFilter Column="ClientID" ControlID="gvwMatches" PropertyName="SelectedDataKey[0]" ComparisionType="Equals" DefaultValue="0" />
                        <data:ImportMatchDetailsFilter Column="ExtID" ControlID="gvwMatches" PropertyName="SelectedDataKey[1]" ComparisionType="Equals" DefaultValue="0" />
                    </Filters>
                </data:SqlParameter>
            </Parameters>
        </data:ImportMatchDetailsDataSource>

    On both the GridView and the FormView, I have DataKeyNames="ClientID,ExtID"

    Now, when I load the form, nothing is selected in the GridView, so I would expect the FormView to show the EmptyDataTemplate, but it is not the case. I checked what is the query being sent to SQL Server, and here are the WhereClause and other parameters passed to the FormView DataSource query:

    '@WhereClause nvarchar(25),@OrderBy nvarchar(4000),@PageIndex int,@PageSize int',@WhereClause=N' (ImportDatabaseID =
    ''1'')',@OrderBy=N'',@PageIndex=0,@PageSize=2147483647

    As one can see, the only filter parameter passed is ImportDatabaseID. What happened to the ClienID and ExtID filters?

    Moreover, when I select a row in the GridView, no query is sent to SQL Server. Is this normal?

    I added a OnSelectedIndexChanged method to the GridView in which I force a DataBind() on the GridView. However, the only filter parameter passed to the query is still ImportDatabaseID.

    Another thing I tried was to add a OneToOneViewRelationship between the GridView and the FormView, but this did not help either.

    Cheers!

    JF 

    • Post Points: 5
  • 02-01-2008 11:59 PM In reply to

    • velum
    • Top 25 Contributor
    • Joined on 07-14-2006
    • Montréal, Qc, Canada
    • Posts 188
    • Points 4,726

    Re: GridView - FormView relationship

     I've done some debuging/tracing and line 127 of the file NetTiers.Web\Data\SqlParameter.cs looks very strange to me:

                        returnValue = (filters[0] as ISqlFilter).GetSqlFilterString(control, filters, isCallback);

    As you can see in my FormView DataSource above, I have three filters, and the filters[ array on the line above also contains 3 elements. However, it looks as if only the first element was taken into account... This looks like a bug to me.

    Cheers!

    JF

     

    Filed under:
    • Post Points: 5
  • 02-02-2008 12:25 AM In reply to

    • velum
    • Top 25 Contributor
    • Joined on 07-14-2006
    • Montréal, Qc, Canada
    • Posts 188
    • Points 4,726

    Re: GridView - FormView relationship

     Also, after some more research, I believe that passing SelectedDataKey[0] as PropertyName is not supported with Filters. Passing this to GetProperty() on line 81 of NetTiers.Entities\EntityUtil.cs returns null.

                    prop = GetProperty(item.GetType(), propertyName);
     

    This is sad because passing SelectedDataKey[0] to an asp:ControlParameter is allowed. It would be nice if this enhancement would be added to .NetTiers.

    Cheers!

    JF

     

    • Post Points: 35
  • 02-21-2008 3:30 PM In reply to

    • IVX
    • Not Ranked
    • Joined on 02-21-2008
    • Posts 3
    • Points 45

    Re: GridView - FormView relationship

    Do you know a way to have a formview or detailsview control be a parent to the grid view? An example would be a Customers table with a foreign key to an Orders table that shows the purchase history(Orders) in a gridview that changes when the detailsview or gridview selection changes.

     I can get this to work with a join and a where clause in SQL, I just don't know how to do it in code.

     Thanks for any help you can lend.

     IVX

    • Post Points: 5
Page 1 of 1 (4 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems