Jump to content
Software FX Community

Multiple fields linking child to master data


lancetb
 Share

Recommended Posts

Is it possible to use more than one field to link a child and master grid together? Specifically, I have two fields that need to be used to narrow the child data down to the correct records for display. Three fields appear in both the master and child data sources:  AccountNumber, TransactionDate, TransactionNumber. The data sources both key on the account number only. Now, the child data needs to filter by the TransactionDate AND the TransactionNumber in order to show the correct records.

 Thanks in advance for help!

Link to comment
Share on other sites

When you connect a grid to a Datasource table having a Key field, the Grid.DataParameterField property is automatically set to this key field and is going to be used for connecting different datasources. In your case, account number should be the grid DataParameterField.value.

Knowing this, when you connect different datasources through a parameter, only one field can be used to connect both datasets.

 

Link to comment
Share on other sites

Thanks for the quick reply!  Ok, so, referring back to my original goal, can you recommend a way to further filter the child records prior to display? In my current configuration, each child record is repeated in every master record, even when they do not belong to the same date as the master record. The appear because they match account numbers.

 Will there be a difference if the child data control keys off of the grid control instead of the query string that both data sources currently key off?

 It feels like the solution is hiding right in front of me, but I don't see it yet. Thanks again.

Link to comment
Share on other sites

Hi,

I think Angel overlooked one property that exists in addition to DataParameterValue: DataParameterValues.  It's a dictionary that lets you set a data source control's ControlParameter's Value property to any field, not just the single field in DataParameterValue.  But the tough part is you have to enter it in by hand. 

In the ControlParameter, you enter something like:

<SelectParameters>

<asp:ControlParameter ControlID="Grid1" Name="property_id" PropertyName="DataParameterValues['agent_id']"Type="Int32" />

 This should help.  Let me know if you run into more problems.
Link to comment
Share on other sites

I'm still stuck here. What I'm looking to do is change the DataParameterField that links Grid1 (master) to Grid2 (detail) into a collection of fields, instead of one field. I didn't want to change the DataParameterValue in the 2 data sources, because I'm currently getting all the correct records.

Link to comment
Share on other sites

I think we've gotten a little confused here.  If I understand it correctly, you have 2 parameters that link the grids together.  In that case, you'd need 2 ControlParameters, each pointing to a different field in DataParameterValues.  It would be much easier if you sent me the markup and code behind.  You can either paste it in the message or email me.  Thanks!

Link to comment
Share on other sites

I don't really have any code behind or markup other than what the designer creates when you first drop a grid onto a web page.

There are two data sources:

SqlDataSource1 gets master records by AccountNumber

SqlDataSource2 gets detail records by AccountNumber

I drag a grid onto the page and point it to DataSource1. Within the properties, I click Add Child Data for a master-detail secondary grid. I point it to DataSource2. I make sure grid1 and grid2 have the same field in DataParameterField - the TransactionDate, which appears in both the master and detail records.

When I run the webapp, the correct master records display. When I drop down the detail for a record, though, I'm getting too many detail items. I'm getting all items from the correct day, but there are multiple records per day. THOSE are identified by TransactionNumber. Each day starts at 1. So, DataParameterField needs to accept both TransactionDate AND TransactionNumber. That would fix it, but I can't select multiple fields when using the properties page to access DataParameterField, in either grid1 or grid2.

Here's a literal display of what I want:

Account123 1/1/07 Transaction1

detail1 $500.00

detail2   $12.00

Account123 1/1/07 Transaction2

detail1 $999.00

 detail2 $17.00

But here's what I'm actually getting:

Account123 1/1/07 Transaction1

detail1 $500.00

detail2  $12.00

detail1 $999.00

 detail2 $17.00

Account123 1/1/07 Transaction2

detail1 $500.00

detail2  $12.00

detail1 $999.00

 detail2 $17.00

Because there is no place to inform the grid1 to grid2 relationship about TransactionNumber. The DataParameterField is set to TransactionDate.

 Hope this clarifies the problem.  Thanks again for all your help.

Link to comment
Share on other sites

  • 2 weeks later...

What you need is two data source parameters on the SqlDataSource2 control, each pointing to a different field in Grid1:

In the SqlDataSource2 markup, you'll need something like:

<asp:ControlParameter ControlID="Grid1" Name="transactionDate" PropertyName="DataParameterValues['TransactionDate']" Type="DateTime" />

<asp:ControlParameter ControlID="Grid1" Name="transactionNumber" PropertyName="DataParameterValues['TransactionNumber']" Type="Int32" />

and change its query to be something like

SelectCommand="Select * from detailTable where transactiondate=@transactionDate and transactionNumber=@transactioNumber

 

The trick is in the DataParameterValues dictionary.  let me know if that helps

Link to comment
Share on other sites

  • 2 months later...

Stephen,

I'm trying to use master/detail technnique with ObjectDatasource (where the code to get the data is defined in the program, not the grid designer).  It works if my child datasource has no parameters.  But I need to give the child a parameter value that depends on which grid row the user selected. The parameter should be the value of one of the datafields.  If you can send an example it would be fine.  Or you could look at my code to see if I am using the wrong approach. The Real Estate example that comes with Grid FX uses an AccessDataSource rather than ObjectDatasource.  It does not try to pass a parameter value from the grid to the program code as I need to do.

 I tried lots of changes. Below is one version.  I get an error when the page loads. 

ObjectDataSource 'GetQtyPickedPerSecondAvgAllDatesDataSource' could not find a non-generic method 'GetQtyPickedPerSecondAvgAllDates' that has parameters: MPL_UserID.

 

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test4.aspx.cs" Inherits="FastFetchMgr.WebSite3._5.Test4" %>

<%@ Register Assembly="GridFX.WebForms" Namespace="GridFX.WebForms" TagPrefix="GridFX" %>

<%@ Register Assembly="ChartFX.WebForms" Namespace="ChartFX.WebForms" TagPrefix="chartfx7" %>

<%@ Register Assembly="ChartFX.WebForms.Gauge" Namespace="ChartFX.WebForms.Gauge"

 TagPrefix="ChartFXGauge" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head id="Head1" runat="server">

 <title>Untitled Page</title>

</head>

<body>

 <form id="form1" runat="server">

 <div>

  <br />

  <asp:Panel ID="CommentPanel" runat="server" CssClass="SampleComment" Width="90%"

HorizontalAlign="Justify">

</asp:Panel>

   <br />

  <br />

  <GridFX:Grid ID="Grid1" DataParameterField="MPL_UserID" runat="server" DataSourceID="GetQtyPickedPerSecondAvgAllUsersDataSource"

Width="100%">

<Columns>

  <GridFX:FieldColumn Field="MPL_UserID" Title="User">

  </GridFX:FieldColumn>

  <GridFX:FieldColumn Field="QtyPickedPerSecond" Title="QtyPickedPerSecond">

  </GridFX:FieldColumn>

  <GridFX:FieldColumn Field="Chart" Title="Picking Record">

  </GridFX:FieldColumn>

</Columns>

<DataFields>

  <GridFX:TextField DataPath="MPL_UserID" Title="User" ReadOnly="true">

<Format>

  <DigitalPanel Width="200px" Height="50px">

  </DigitalPanel>

</Format>

  </GridFX:TextField>

  <GridFX:NumberField DataPath="QtyPickedPerSecond" ReadOnly="true">

<Format Decimals="2" Display="Gauge">

  <GaugeMarkup>

<ChartFXGauge:HorizontalGauge ID="HorizontalGauge1" runat="server" BackColor="Transparent"

  Height="18px" Width="60px">

  <Border Visible="False"></Border>

  <Titles>

<ChartFXGauge:Title Text="%v" Visible="False">

  <Layout Alignment="BottomCenter"></Layout>

</ChartFXGauge:Title>

  </Titles>

  <Scales>

<ChartFXGauge:LinearScale Color="Transparent" ColorTransparency="0" FillerVolume="0.9"

  Max="1000" Min="0" Size="0.95" Thickness="0.9">

  <Indicators>

<ChartFXGauge:Filler UseRangeColor="Section" Value="0"></ChartFXGauge:Filler>

  </Indicators>

  <Bar Color="Transparent">

<Border Thickness="0.05"></Border>

  </Bar>

  <Sections>

<ChartFXGauge:Section Bar-Color="255, 0, 0" Bar-Visible="False" Max="0.4" Min="-Infinity">

</ChartFXGauge:Section>

<ChartFXGauge:Section Bar-Color="255, 255, 0" Bar-Visible="False" Max="0.7" Min="0.4">

</ChartFXGauge:Section>

<ChartFXGauge:Section Bar-Color="124, 252, 0" Bar-Visible="False" Max="Infinity"

  Min="0.7">

</ChartFXGauge:Section>

  </Sections>

  <Tickmarks Visible="False">

  </Tickmarks>

</ChartFXGauge:LinearScale>

  </Scales>

</ChartFXGauge:HorizontalGauge>

  </GaugeMarkup>

</Format>

  </GridFX:NumberField>

  <GridFX:ChartField DataSourceID="GetQtyPickedPerSecondAvgAllDatesDataSource"

UniqueID="Chart">

<Chart>

  <Series>

<chartfx7:SeriesAttributes Text="Amount"></chartfx7:SeriesAttributes>

  </Series>

  <DataSourceSettings>

<Fields>

  <chartfx7:FieldMap DisplayName="QtyPickedPerSecond" Name="QtyPickedPerSecond" Usage="Value">

  </chartfx7:FieldMap>

  <chartfx7:FieldMap DisplayName="DatePicked" Name="DatePicked" Usage="XValue"></chartfx7:FieldMap>

</Fields>

  </DataSourceSettings>

  <AllSeries PointLabelOrganizer-AutoArrange="True" PointLabelOrganizer-Enabled="True"

PointLabels-BackColor="Transparent" PointLabels-BorderColor="Transparent">

  </AllSeries>

  <LegendBox Border="None" Visible="False">

  </LegendBox>

  <Titles>

<chartfx7:TitleDockable Text="Picking Record"></chartfx7:TitleDockable>

  </Titles>

</Chart>

  </GridFX:ChartField>

</DataFields>

<ToolBar Visible="False">

</ToolBar>

<Border Type="None" />

<ItemDetails>

  <ContentTemplate>

<GridFX:FieldContainer ID="ChartField1" runat="server" Field="Chart">

</GridFX:FieldContainer>

  </ContentTemplate>

</ItemDetails>

<TitleBar Title="User" Visible="True" Subtitle="Picking" Style-HorizontalAlign="Left">

  <Image Icon="Index" />

</TitleBar>

  </GridFX:Grid>

  <asp:ObjectDataSource ID="GetQtyPickedPerSecondAvgAllDatesDataSource" runat="server"

TypeName="FastFetchMgr.WebSite3._5.Test3" SelectMethod="GetQtyPickedPerSecondAvgAllDates"

EnablePaging="false">

<SelectParameters>

  <asp:ControlParameter ControlID="Grid1" Name="MPL_UserID" PropertyName="DataParameterValue"

Type="String" />

</SelectParameters>

</asp:ObjectDataSource>

  <asp:ObjectDataSource ID="GetQtyPickedPerSecondAvgAllUsersDataSource" runat="server"

TypeName="FastFetchMgr.WebSite3._5.Test3" SelectMethod="GetQtyPickedPerSecondAvgAllUsers_ForDataSource"

EnablePaging="false">

</asp:ObjectDataSource>

 </div>

 </form>

</body>

</html>

 

namespace FastFetchMgr.WebSite3._5

{

  public partial class Test4 : System.Web.UI.Page

  {

  public List<FastFetchMgr.Entity.User.UserAvgQtyPickedEntity> GetQtyPickedPerSecondAvgAllUsers_ForDataSource()

  {

  DateTime QtyPickedPerSec_FromDate = DateTime.Parse("3/19/2008");

  DateTime QtyPickedPerSec_ToDate = DateTime.Parse("4/19/2008");

  int WH_ID = 5;

  return FastFetchMgr.Library.Manager.MgtPickLineManager.GetQtyPickedPerSecondAvgAllUsersCustomList(WH_ID, QtyPickedPerSec_FromDate, QtyPickedPerSec_ToDate);

  }

  public List<FastFetchMgr.Entity.User.UserAvgQtyPickedEntity> GetQtyPickedPerSecondAvgAllDates(String MPL_UserID)

  {

  DateTime QtyPickedPerSec_FromDate = DateTime.Parse("3/19/2008");

  DateTime QtyPickedPerSec_ToDate = DateTime.Parse("4/19/2008");

  //String sUserID = "Bate";

  int WH_ID = 5;

  return FastFetchMgr.Library.Manager.MgtPickLineManager.GetQtyPickedPerSecondAvgAllDates(MPL_UserID, WH_ID, QtyPickedPerSec_FromDate, QtyPickedPerSec_ToDate);

  }

  }

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...