asp:SqlDataSource with parameters

  • Thread starter Thread starter E. Kwong
  • Start date Start date
E

E. Kwong

I just want to select records with a certain date field > today's date:

<asp:SqlDataSource ID="src1" runat="server" ConnectionString="<%$
ConnectionStrings:xyz %>"

SelectCommand="SELECT * FROM [Events] WHERE [Startdate] > ? "
OnSelected="src1_Selected">

<SelectParameters>

<asp:Parameter Name="Startdate" Type="DateTime" />

</SelectParameters>

</asp:SqlDataSource>

---------------------

protected void srcEvents_Selected(object sender,
SqlDataSourceStatusEventArgs e)

{

e.Command.Parameters["Startdate"].Value = DateTime.Today;

}

-------------------

I have a list control bind to this data source but when executed the list
doesn't show. That means no record is selected. I know there are
qualifying records since I input them myself in SQL server.

Am newbie so I must code something wrong. Any insignt appreciated.
 
The problem is that the Selected event does not occur until *after* data has
been retrieved from the database. Try setting the parameter in the PageLoad
handler.
 
Back
Top