You could create custom parameters like so
http://fredrik.nsquared2.com/viewpost.aspx?PostID=355
but it might be easier to do the following:
We add a selecting event to the data source which will retrieve a public property from the user control and set it as a parameter. The public property of the user control retrieves the value of some web control like a textbox and exposes it as a property.
Given the following SqlDataSource
<asp:sqlDataSource ID="EmployeeDetailsSqlDataSource"
SelectCommand="SELECT EmployeeID, LastName, FirstName FROM Employees WHERE EmployeeID = @EmpID"
<SelectParameters>
<asp:Parameter Name="EmpID" Type="Int32" DefaultValue="0" />
</SelectParameters>
</asp:sqlDataSource>
We add a selecting event like so
protected void EmployeeDetailsSqlDataSource_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
e.Command.Parameters["@EmpID"].Value = MyUserControl.EmpID;
}
The UserControl has a property like so:
public int EmployeeID {
get {
return Convert.ToInt32(TextBox1.Text);
}
}
Where TextBox1 is where the user enters the employeeID. You could also use ViewState to store the EmployeeId property in case you want to persist across postbacks (depending on your scenario).