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

GridDropDownColumn with LinqDataSource and WhereParameters

5 Answers 111 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 23 Jun 2009, 09:13 PM
I can't find any documentation on how to use LinqDataSource with WhereParameters on a GridDropdownColumn.

The reason is, I have a dropdown column in a DetailTable which I want to be filtered by the parent table. Since there is no ID on a DetailTable I can't use ControlParameter.  I tried using just Parameter but it didn't seem to work, the parent DataKeyValues don't get passed to the LinqDataSource, I believe. 

I can post sample code if that would help...  Thanks.

5 Answers, 1 is accepted

Sort by
0
Kevin
Top achievements
Rank 1
answered on 24 Jun 2009, 02:22 AM
To clarify:
Imagine the following Grid structure with 2 DetailTables inside:

Cars
| - Models
| - - Parts

So with this structure I can manage a Car, different models of that car, and the parts each car model has.  The Parts table will bind off of a table like CarModelParts for example. But let's say I create a new model, I want to add a CarModelPart from a master list of car parts which is stored in a separate table (AllCarParts, for example).  This list of parts however, is specific to a CarModel.  The amount of each parts per model varies.

So I would like a GridDropdownColumn in the Parts DetailTable which binds off AllCarParts but filtered by CarModelID (which would be a DataKeyName in the Models DetailTable.

CarModelParts (third detail table) is of course filtered by CarModelID, but I would like to filter a GridDropdownColumn in the Parts table with CarModelID as well.  Is this possible?
0
Kevin
Top achievements
Rank 1
answered on 24 Jun 2009, 08:56 PM
It seems like DataKeyValues are not passed to the LinqDataSource WhereParameters for DetailTable GridDropDownColumns. If this is true, it seems like a major bug.  How else are you supposed to filter grid dropdown columns for detail tables?
0
Kevin
Top achievements
Rank 1
answered on 24 Jun 2009, 10:23 PM
Here's a demo solution file that demonstrates this behavior:
RadGridDropdownTest1.zip

In this example, you can add an "element" such as a Textbox or a Hyperlink.  You can then add an attribute to this element by using the detail table.  Problem is, I need the dropdown column in the detail table to only display attributes relative to the selected element...

You should not be able to put a "url" attribute on a Textbox and you should not be allowed to put a "maxlength" attribute on a Hyperlink.
0
Bruno
Top achievements
Rank 2
answered on 26 Jun 2009, 01:25 PM
May I ask why do you think it should be passed in the first place? I don't think it is expected as how will the grid know to pass the datakey and to which parameter it should be mapped having in mind that this is a datasource linked to a control in a detail table.

In scenarios like yours I would  use a template column similar to the following:

                      <telerik:GridTemplateColumn DataField="attributeID" HeaderText="Attribute">                             
                            <EditItemTemplate> 
                                <asp:Label Style="display: none;" runat="server" ID="Label" Text='<%# CType(CType(Container, GridEditableItem).OwnerTableView.ParentItem,GridDataItem).GetDataKeyValue("elementID") %>' /> 
                                <asp:LinqDataSource ID="LinqDataSource_Attributes" runat="server" ContextTypeName="DataClassesDataContext" 
                                    EnableDelete="True" EnableInsert="True" EnableUpdate="True" TableName="Attributes" 
                                    Where="elementID == Int32(@elementID)"
                                    <WhereParameters> 
                                        <asp:ControlParameter Name="elementID" Type="Int32" ControlID="Label" PropertyName="Text" /> 
                                    </WhereParameters> 
                                </asp:LinqDataSource> 
                                <asp:DropDownList runat="server" ID="DropDownList1" DataSourceID="LinqDataSource_Attributes" 
                                    DataTextField="name" DataValueField="attributeID" SelectedValue='<%#Bind("attributeID") %>' /> 
                            </EditItemTemplate> 
                        </telerik:GridTemplateColumn> 

-- Bruno

0
Kevin
Top achievements
Rank 1
answered on 26 Jun 2009, 02:49 PM
Yes, a template column is something I thought about doing, but did not want to declare a new LinqDataSource for each entry.

I submitted a ticket and the solution turned out to be very simple. You must handle the DetailTableDataBind event and use code such as this:

        If e.DetailTableView.Name = "Attributes" Then 
            LinqDataSource_Attributes.WhereParameters("elementID").DefaultValue = e.DetailTableView.ParentItem.GetDataKeyValue("elementID"
        End If 


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