This is a migrated thread and some comments may be shown as answers.

How can I create a Hierarchical Grid with multiple key fields?

1 Answer 120 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 26 Aug 2010, 03:41 PM
I have a set of 2 tables I am trying to display in a hierarchical grid. 

Table 1 is a list of State Licenses.  A rep has an identifying "ProducerNumber" and then a "State", which can appear more than once in the table, plus some other details.

Table 2 is a list of State details.  It has the same "ProducerNumber", "State", and then the "Details" line. 

So in my table I want the top level grid to be the list of States, and once a state is expanded the Details lines for that state will be displayed underneath.  The details lines need to match on 3 qualties: "ProducerNumber", "State", and "Class" to be unique.

I've tried setting my table up as per the sample at: http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/declarativerelations/defaultvb.aspx but I only ever get any details for the top level display.  If I click to expand any of the states it's simply blank.

Can anyone help?  Are there more examples of how to set this up?  Do you need to see my code?

1 Answer, 1 is accepted

Sort by
0
Kevin
Top achievements
Rank 1
answered on 26 Aug 2010, 08:55 PM
I guess I was expecting a reply more quickly than was realistic. 

Anyway, I spent the day messing around with this and now have it working.

To answer my own question, (to help any future searchers on this topic), there are 3 key parts to make it work with a table that requires more than 1 field to establish uniqueness.

1) In the "MasterTableView" element, the "DataKeyNames" property must contain both of your values i.e:
<MasterTableView DataSourceID="SqlDataSource1" DataKeyNames="stateID, cityID"

 

 

2) The "ParentTableRelation" must contain an entry for each field in the "DataKeyNames" list.

<ParentTableRelation
     <telerik:GridRelationFields DetailKeyField="stateID" MasterKeyField="stateID" /> 
     <telerik:GridRelationFields DetailKeyField="cityID" MasterKeyField="cityID" /> 
</ParentTableRelation>

3) The DataSource for the sub-table must contain a where clause utilizing both values from the "DataKeyName" field, both of which must be set up as Session Parameters with the "SessionField" set to the same exact name as the "DataKeyNames".

 

<asp:SqlDataSource ID="SqlDataSource2" 
     ConnectionString="<%$ ConnectionStrings:PDBConnectionString %>"
     SelectCommand="SELECT * FROM LOAs Where stateID = @stateID and 
     cityID = @cityID" runat="server"> 
     <SelectParameters
          <asp:SessionParameter Name="stateID" SessionField="stateID" Type="string" /> 
          <asp:SessionParameter Name="cityID" SessionField="cityID" Type="string" /> 
     </SelectParameters
</asp:SqlDataSource

 

 

Tags
Grid
Asked by
Kevin
Top achievements
Rank 1
Answers by
Kevin
Top achievements
Rank 1
Share this question
or