trouble with Master-Details list

  • Thread starter Thread starter brian.newman
  • Start date Start date
B

brian.newman

I'm trying to link a gridview to another gridview in a Master-Details
architecture. But the Details list isn't filtering like it is
suppossed to. It will show all items on page load and it won't remove
any items when an item in the Masters list is selected. It shouldn't
show anything until an item in the Master's list is selected and then
only show the details which are associated with the selected item in
the Masters list.
I'm new to ASP.NET (one of the last straglers moving from VBScript)
and, so, I'm probably doing something pretty stupid, but some help
would be really appreciated.
Here's the code

<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile=""

SelectCommand="SELECT DISTINCT org FROM Orgs"
OnSelecting="AccessDataSource1_Selecting1"></asp:AccessDataSource>

<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False"

DataSourceID="AccessDataSource1" Style="z-index: 100; left:
6px; position: absolute;

top: 7px" DataKeyNames="org"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
BorderStyle="None" PageSize="20">

<Columns>

<asp:HyperLinkField DataNavigateUrlFields="org"
DataNavigateUrlFormatString="Details.aspx?field={0}"

DataTextField="org" />

</Columns>

</asp:GridView>



<asp:AccessDataSource ID="AccessDataSource2" runat="server"
DataFile=""

OnSelecting="AccessDataSource2_Selecting1"
SelectCommand="SELECT Orgs.org, ThreeLetter.[position],
ThreeLetter.location, [user].Name, rights.Type FROM (((Orgs INNER JOIN
ThreeLetter ON Orgs.ID = ThreeLetter.Orgs_ID) INNER JOIN rights ON
ThreeLetter.officeKey = rights.officeKey) INNER JOIN [user] ON
rights.userKey = [user].userKey) ORDER BY Orgs.org"
FilterExpression="Org='@Org'">

<FilterParameters><asp:ControlParameter Name="Org"
ControlID="GridView1" PropertyName="SelectedValue"
/></FilterParameters>

</asp:AccessDataSource>

<asp:GridView ID="GridView2" runat="server"
AutoGenerateColumns="False" DataKeyNames="org,Name"

DataSourceID="AccessDataSource2" Style="z-index: 103; left:
115px; position: absolute;

top: 9px">

<Columns>

<asp:CommandField HeaderText="Edit Rights"
ShowEditButton="True" ShowHeader="True" />

<asp:BoundField DataField="position"
HeaderText="position" SortExpression="position" />

<asp:BoundField DataField="location"
HeaderText="location" SortExpression="location" />

<asp:BoundField DataField="Type" HeaderText="Type"
SortExpression="Type" />

</Columns>

</asp:GridView>
 
Hi Brian,

The OleDb provider (used by AccessDataSource) uses ordered parameters, not named parameters. Also, because you have @Org quoted in
FilterExpression it's being used as a string literal. Try naming your parameter OrgParam and using it as is, without a prefix or
quotes directly in a WHERE clause of your query:

SELECT Orgs.Org
[...]
WHERE Org = OrgParam

The details grid should be hidden, by default, until the page is posted back when the user selects a master grid row and if there is
at least one child record to be displayed.

--
Dave Sexton

I'm trying to link a gridview to another gridview in a Master-Details
architecture. But the Details list isn't filtering like it is
suppossed to. It will show all items on page load and it won't remove
any items when an item in the Masters list is selected. It shouldn't
show anything until an item in the Master's list is selected and then
only show the details which are associated with the selected item in
the Masters list.
I'm new to ASP.NET (one of the last straglers moving from VBScript)
and, so, I'm probably doing something pretty stupid, but some help
would be really appreciated.
Here's the code

<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile=""

SelectCommand="SELECT DISTINCT org FROM Orgs"
OnSelecting="AccessDataSource1_Selecting1"></asp:AccessDataSource>

<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False"

DataSourceID="AccessDataSource1" Style="z-index: 100; left:
6px; position: absolute;

top: 7px" DataKeyNames="org"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
BorderStyle="None" PageSize="20">

<Columns>

<asp:HyperLinkField DataNavigateUrlFields="org"
DataNavigateUrlFormatString="Details.aspx?field={0}"

DataTextField="org" />

</Columns>

</asp:GridView>



<asp:AccessDataSource ID="AccessDataSource2" runat="server"
DataFile=""

OnSelecting="AccessDataSource2_Selecting1"
SelectCommand="SELECT Orgs.org, ThreeLetter.[position],
ThreeLetter.location, [user].Name, rights.Type FROM (((Orgs INNER JOIN
ThreeLetter ON Orgs.ID = ThreeLetter.Orgs_ID) INNER JOIN rights ON
ThreeLetter.officeKey = rights.officeKey) INNER JOIN [user] ON
rights.userKey = [user].userKey) ORDER BY Orgs.org"
FilterExpression="Org='@Org'">

<FilterParameters><asp:ControlParameter Name="Org"
ControlID="GridView1" PropertyName="SelectedValue"
/></FilterParameters>

</asp:AccessDataSource>

<asp:GridView ID="GridView2" runat="server"
AutoGenerateColumns="False" DataKeyNames="org,Name"

DataSourceID="AccessDataSource2" Style="z-index: 103; left:
115px; position: absolute;

top: 9px">

<Columns>

<asp:CommandField HeaderText="Edit Rights"
ShowEditButton="True" ShowHeader="True" />

<asp:BoundField DataField="position"
HeaderText="position" SortExpression="position" />

<asp:BoundField DataField="location"
HeaderText="location" SortExpression="location" />

<asp:BoundField DataField="Type" HeaderText="Type"
SortExpression="Type" />

</Columns>

</asp:GridView>
 
Back
Top