Populating Datasource InsertParameter

2 posts, 0 answers
  1. Neil N
    Neil N avatar
    89 posts
    Member since:
    Aug 2012

    Posted 18 Jun 2015 Link to this post

    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>

     

  2. Viktor Tachev
    Admin
    Viktor Tachev avatar
    2299 posts

    Posted 23 Jun 2015 Link to this post

    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
Back to Top