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

Populating Datasource InsertParameter

1 Answer 179 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Neil N
Top achievements
Rank 1
Iron
Veteran
Iron
Neil N asked on 18 Jun 2015, 03:53 PM

I know I can do this with code, but is there no way to populate a Datasource InsertParameter from a control?  In this case I want to update the datasource of a second grid with a value in the selected row of the first grid.

<asp:SqlDataSource ID="dsCommodities" runat="server" ConnectionString="<%$ ConnectionStrings:Market_Directory.My.MySettings.dbConnStr %>" DeleteCommand="DELETE FROM [Commodity] WHERE [CommodityID] = @CommodityID" InsertCommand="INSERT INTO [Commodity] ([CommodityName], [SortOrder], [Published], [MaterialID]) VALUES (@CommodityName, @SortOrder, @Published, @MaterialID)" SelectCommand="SELECT [CommodityID], [CommodityName], [SortOrder], [Published], [MaterialID] FROM [Commodity] WHERE ([MaterialID] = @MaterialID) ORDER BY [SortOrder]" UpdateCommand="UPDATE [Commodity] SET [CommodityName] = @CommodityName, [SortOrder] = @SortOrder, [Published] = @Published, [MaterialID] = @MaterialID WHERE [CommodityID] = @CommodityID">
    <DeleteParameters>
        <asp:Parameter Name="CommodityID" Type="Int32" />
    </DeleteParameters>
    <InsertParameters>
        <asp:Parameter Name="CommodityName" Type="String" />
        <asp:Parameter Name="SortOrder" Type="Int32" />
        <asp:Parameter Name="Published" Type="Boolean" />
        <asp:ControlParameter ControlID="grdMaterials" DefaultValue="-1" Name="MaterialID" PropertyName="SelectedValue" Type="Int32" />
    </InsertParameters>
    <SelectParameters>
        <asp:ControlParameter ControlID="grdMaterials" DefaultValue="-1" Name="MaterialID" PropertyName="SelectedValue" Type="Int32" />
    </SelectParameters>
    <UpdateParameters>
        <asp:Parameter Name="CommodityName" Type="String" />
        <asp:Parameter Name="SortOrder" Type="Int32" />
        <asp:Parameter Name="Published" Type="Boolean" />
        <asp:Parameter Name="MaterialID" Type="Int32" />
        <asp:Parameter Name="CommodityID" Type="Int32" />
    </UpdateParameters>
</asp:SqlDataSource>

 

1 Answer, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 23 Jun 2015, 07:13 AM
Hi Neil,

In the provided code it seems that you have a ControlParameter added to the InsertParameters. With this setup you should be able to use the selected item from the grdMaterials grid.

In order for the functionality to work you need to ensure that the MaterialID field is added to the DataKeyNames collection of grdMaterials. Also selection should be enabled for the grid.

Similar approach is used in the demo linked below.


I hope this helps.


Regards,
Viktor Tachev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Neil N
Top achievements
Rank 1
Iron
Veteran
Iron
Answers by
Viktor Tachev
Telerik team
Share this question
or