GridView SelectParameters

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?
 
B

Brock Allen

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top