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

Grid with DropDownList datasource Select parameter issue

4 Answers 550 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 08 Nov 2016, 06:46 PM

Hello,

I thought this would be straight-forward, and maybe it is -- I am probably missing something obvious.  I have a RadGrid that has DropDownList inside a GridTemplateColumn.

<telerik:RadGrid ID="RadGridTestsInstruments" runat="server"
                                        DataSourceID="SqlDataSourceTestsInstruments"
                                        AutoGenerateColumns="False"
                                        AllowSorting="True"
                                        Height="220px"
                                        Width="430px"
                                        AllowMultiRowSelection="false"
                                        AllowAutomaticUpdates="True"
                                        OnItemUpdated="RadGridTestsInstruments_ItemUpdated"
                                        style="margin-top: 0px">
                                        <GroupingSettings CollapseAllTooltip="Collapse all groups"></GroupingSettings>
                                        <ClientSettings AllowKeyboardNavigation="true"
                                            EnableRowHoverStyle="true">
                                            <Selecting AllowRowSelect="true"></Selecting>
                                            <Scrolling AllowScroll="True" UseStaticHeaders="True" />
                                        </ClientSettings>
                                        <MasterTableView
                                            DataSourceID="SqlDataSourceTestsInstruments"
                                            DataKeyNames="set_test_id,test_id"
                                            EditMode="Batch">
                                            <BatchEditingSettings EditType="Cell"/>
                                            <Columns>
                                                <telerik:GridBoundColumn DataField="set_test_id" HeaderText="set_test_id" SortExpression="set_test_id" UniqueName="set_test_id" DataType="System.Int32" ReadOnly="True" Display="False">
                                                </telerik:GridBoundColumn>
                                                <telerik:GridBoundColumn DataField="test_id" DataType="System.Int32" HeaderText="test_id" ReadOnly="True" SortExpression="test_id" UniqueName="test_id" Display="False">
                                                </telerik:GridBoundColumn>
                                                <telerik:GridBoundColumn DataField="grid_instrument_id" DataType="System.Int32" HeaderText="grid_instrument_id" ReadOnly="True" SortExpression="grid_instrument_id" UniqueName="grid_instrument_id" Display="False">
                                                </telerik:GridBoundColumn>
                                                <telerik:GridBoundColumn DataField="test" HeaderText="Test" SortExpression="test" UniqueName="test" ReadOnly="True">
                                                </telerik:GridBoundColumn>
                                                <telerik:GridTemplateColumn HeaderText="Instrument" HeaderStyle-Width="110px" UniqueName="instrument_id" DataField="instrument_id" AllowFiltering="false">
                                                    <ItemTemplate>
                                                        <%# Eval("instrument") %>
                                                    </ItemTemplate>
                                                    <EditItemTemplate>
                                                        <telerik:RadDropDownList RenderMode="Lightweight" runat="server" ID="RadDropDownListInstruments"
                                                            DataField="set_test_id"
                                                            DataValueField="instrument_id"
                                                            DataTextField="instrument"
                                                            AllowCustomText="true"
                                                            EmptyMessage="Choose Instrument"
                                                            DataSourceID="SqlDataSourceInstruments"
                                                            Width="100px">
                                                        </telerik:RadDropDownList>
                                                    </EditItemTemplate>
                                                </telerik:GridTemplateColumn>
                                                <telerik:GridBoundColumn DataField="workflow_id" DataType="System.Int32" HeaderText="workflow_id" ReadOnly="True" UniqueName="workflow_id" Display="False">
                                                </telerik:GridBoundColumn>
                                                <telerik:GridBoundColumn DataField="workflow" HeaderText="Workflow" SortExpression="workflow" UniqueName="workflow" ReadOnly="True">
                                                </telerik:GridBoundColumn>
                                            </Columns>
                                        </MasterTableView>
                                    </telerik:RadGrid>

 

I need the DropDownList datasource to have a parameter from a cell value on the selected row. The DataKeyName also contains the same value that could be used as a parm.

<asp:SqlDataSource ID="SqlDataSourceInstruments" runat="server" ConnectionString="<%$ ConnectionStrings:MineLIMSConnection %>"
            SelectCommand="SELECT distinct i.instrument_id, i.instrument, tst.set_test_id
                                FROM instruments i
                                Inner Join tests_instruments ti on ti.instrument_id = i.instrument_id
                                Inner Join ml_temp_dest_sets_tests tst on tst.test_id = ti.test_id
                            WHERE tst.set_test_id = @set_test_id">
            <SelectParameters>
                <asp:ControlParameter ControlID="RadGridTestsInstruments" DefaultValue="999" Name="set_test_id" PropertyName="SelectedValues['set_test_id']" Type="Int32" />
            </SelectParameters>
        </asp:SqlDataSource>

 

When I try to use a ControlParameter from the Grid itself as shown above, I get this error:

Could not find control 'RadGridTestsInstruments' in ControlParameter 'set_test_id'.

<asp:SqlDataSource ID="SqlDataSourceInstruments" runat="server" ConnectionString="<%$ ConnectionStrings:MineLIMSConnection %>"
            SelectCommand="SELECT distinct i.instrument_id, i.instrument, tst.set_test_id
                                FROM instruments i
                                Inner Join tests_instruments ti on ti.instrument_id = i.instrument_id
                                Inner Join ml_temp_dest_sets_tests tst on tst.test_id = ti.test_id
                            WHERE tst.set_test_id = @set_test_id">
            <SelectParameters>
                <asp:Parameter Name="set_test_id" Type="Int32" />
            </SelectParameters>
        </asp:SqlDataSource>

 

If I just use a Parameter from the Grid itself as shown above, there is nothing returned.

I am thinking that I should be going this route, but I must not be setting the right field on the Grid and/or dropdown to set the parameter properly.

If I remove the parameter completely, I get data, but from all rows in the Grid, which is incorrect.

Thanks in advance,

g.

 

 

 

 

4 Answers, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 11 Nov 2016, 02:18 PM
Hi Jeff,

The error you are seeing is thrown by the SqlDataSource and is usually shown when a nested control is set to the ControlID property. If the RadGrid is nested in another control, would you place it on the page and see if it makes a difference. You can also try using the complete UniqueID for the Grid as ControlID.

As for the other approach, would you place the SqlDataSource in the EditItemTemplate with the RadDropDownList and see if the Parameter is taken into account. Also, please ensure that the SelectedValue for the dropdown is set as it would display the correct value.

With that said, the RadDropDownList does not have a DataField property. Please remove it from the markup.

As an alternative approach you can bind the dropdown programmatically. In the link below you can find an example that illustrates how you can add dropdown controls in the RadGrid.



Regards,
Viktor Tachev
Telerik by Progress
Check out the new UI for ASP.NET Core, the most complete UI suite for ASP.NET Core development on the market, with 60+ tried-and-tested widgets, based on Kendo UI.
0
Jeff
Top achievements
Rank 1
answered on 17 Nov 2016, 05:51 PM

Thanks for the assistance Viktor.

I have come much further but have reached another wall.  I believe the complexity is due to the grid being in 'Batch' mode.

I have worked with all 3 of your suggestions and here is what I've found (not in order).

  • Alternate approach to bind the dropdown programmatically: This worked for producing the correct items in the dropdown, however the postback created other issues with persisting the batch updates occurring on the grid.
  • Other approach to place the SqlDataSource in the EditItemTemplate: The SelectedValue is set properly, but no data is returned.  I think this may be due to not having a Postback.
  • Using the complete UniqueID for the ControlID:  This has given me the best results, but is still not working properly.  I have used JavaScript to make sure the grid's selected row is set.  I even tried using a HiddenField and a hidden textbox to hold the ControlID value.  It all looks good with a trip to the server.  The dropdown doesn't respond to the current ControlID value that is set Client-side. Only if I postback, the ControlID works properly.

Due to the batch editing nature of the Grid, is there a way to set a parameter Client-side that would be immediately available to the SqlDataSource?

Best regards,

g.

0
Viktor Tachev
Telerik team
answered on 22 Nov 2016, 02:49 PM
Hi Jeff,

Probably the easiest way to have such parameter available to the SqlDataSource would be via a HiddenField. You can use JavaScript and update the HiddenField when another row is selected/edited. Then the SqlDataSource should be able to use the value and return the correct data.

However, note that with Batch Edit mode there is only one editor rendered per column. There is an internal client-side logic that handles showing and hiding the editor when a cell is edited.

With that said, if you would like to have a feature similar to cascading dropdown controls you should consider using an approach similar to the one illustrated in the code-library below. Please check it out and let me know how it works for you.



Regards,
Viktor Tachev
Telerik by Progress
Telerik UI for ASP.NET AJAX is ready for Visual Studio 2017 RC! Learn more.
0
Jeff
Top achievements
Rank 1
answered on 09 Dec 2016, 02:03 PM

Hello Viktor,

I did go the route of using a HiddenField.  The quandary of needing a postback for updating the parameter on the SqlDataSource along with not being able to postback due to the batch editing was challenging.  However, the __doPostBack method on the HiddenField along with allowing a physical update on the GridTemplateColumn DropDownList selection change was the solution for me.  I think if I had multiple cells to batch edit, I may still have some issues, but all is well in this case.

Thanks,

g.

 

 

Tags
Grid
Asked by
Jeff
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Jeff
Top achievements
Rank 1
Share this question
or