GridView SelectParameters

  • Thread starter Thread starter Mike P
  • Start date Start date
M

Mike P

I am using a GridView with 3 SelectParameters 2 of which are
ControlParameters, but the third of my SelectParameter values is derived
through my code rather than a QueryString, Control etc, so I need to add
my select parameters programmatically.

Here are my 2 ControlParameters are they were originally :

<SelectParameters>
<asp:ControlParameter Name="Month"
ControlID="ddlMonth" PropertyName="SelectedValue" />
<asp:ControlParameter Name="Year" ControlID="ddlYear"
PropertyName="SelectedValue" />
</SelectParameters>

And here are all 3 of my parameters declared within my Page_Load instead
:

SqlDataSource1.SelectParameters.Add("UserKey", TypeCode.Int32,
UserKey.ToString());
SqlDataSource1.SelectParameters.Add("Month", TypeCode.String,
ddlMonth.SelectedValue);
SqlDataSource1.SelectParameters.Add("Year", TypeCode.String,
ddlYear.SelectedValue);


Is this the right way to do this programmatically?
 
You don't need to manually add the ones that you've already done declaratively
(that's the point of the declarative model). For the 3rd parameter that you
must add dynamically, you can do it either in Page_Load or you can do it
in one of the Data Source Control's pre-processing events, like Selecting,
Updating, Inserting or Deleting.

-Brock
http://staff.develop.com/ballen
 
Back
Top