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.
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.
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.
<
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.