asp:SqlDataSource with parameters

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

Robert Dunlop

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.
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top