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

RadGrid - Order of Parameters in DS Random

1 Answer 71 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marbry
Top achievements
Rank 1
Marbry asked on 31 Aug 2011, 04:59 PM
So I'm using the grid to manage a number of reference tables.  Most just have the identity and a text field, one has several text fields.  I'm doing it as generically as possible, with one grid and one SQLDataSource on the page, and 4 stored procs with generic parameters for insert, update, delete and select.  I have corresponding params for each action defined declaratively in the datasource.
<SelectParameters>
            <asp:Parameter Name="itemType" Type="String" />
        </SelectParameters>
        <InsertParameters>
            <asp:Parameter Name="itemType" Type="String" />
            <asp:Parameter Name="itemValue" Type="String" />
            <asp:Parameter Name="itemValue2" Type="String" />
            <asp:Parameter Name="itemValue3" Type="String" />
        </InsertParameters>
        <DeleteParameters>
            <asp:Parameter Name="itemID" Type="Int32" />
            <asp:Parameter Name="itemType" Type="String" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="itemID" Type="Int32" />
            <asp:Parameter Name="itemType" Type="String" />
            <asp:Parameter Name="itemValue" Type="String" />
            <asp:Parameter Name="itemValue2" Type="String" />
            <asp:Parameter Name="itemValue3" Type="String" />
        </UpdateParameters>


I'm handling the Updating, Selecting etc... events for the datasource, and set the value of the datasource params there before it runs each command.
protected void dsActivity_Deleting(object sender, SqlDataSourceCommandEventArgs e)
        {
            int paramcount = e.Command.Parameters.Count;
  
            e.Command.Parameters["@itemID"].Value = e.Command.Parameters["@" + lstReference.Items[lstReference.SelectedIndex].Value + "ID"].Value.ToString();
            e.Command.Parameters["@itemType"].Value = lstReference.Items[lstReference.SelectedIndex].Value;
  
            while (e.Command.Parameters.Count > 2)
                e.Command.Parameters.RemoveAt(e.Command.Parameters.Count - 1);
        }


The problem I had to work around was that although the grid appends the field values to the params in the datasource events, the order of them is not consistent.  So that makes it hard to handle them in a generic manner since I can't use the index to reference them, not knowing what param might be in a given position.

I've worked around this since I ran into it, but it would have been a lot cleaner if I could depend on the parameters to be added in the same order.  This would be handy for certain scenarios like this if it would build that with the params in the corresponding order they were originally retrieved.

1 Answer, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 02 Sep 2011, 09:42 AM
Hi Marbry,

 The grid internally does not change the order of the parameters. Simply the datasource control itself does not guarantee that the parameters will be ordered in the exact same way that you specified in the markup. The parameters collections are populated and managed internally by the datasource control and the order of the elements may differ from the originally specified. That is why it is better always to address the parameters by their name rather than index.

Regards,
Marin
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
Grid
Asked by
Marbry
Top achievements
Rank 1
Answers by
Marin
Telerik team
Share this question
or