Thursday, March 29, 2012

Changing the source wth a button

Hi,

I have this Gridview in which I show attendees to a course (per course)

In the same gridview I want to be able (by clicking a button) to show all attendees to all courses simply by leaving out a part of the SQL;

WHERE Eventid = @.eventid (resulting in all attendees no matter what course)

In other words how can I alter the selectcommand of the SQLDataSource?

Seems simple, but can't hack it.

Thanks in advance,

Lx

Hello my friend,

There are several ways to do this. A straightforward one would be to reserve a number to mean ALL of them, like so: -

SELECT * FROM MyTable WHERE (EventID = @.EventID OR @.EventID = -1)

Now just pass in -1 when you want to get all of them.

Kind regards

Scotty

|||

Hi,

Thank you,

The actual SQL is not a problem. I want to change the Selectcommand using a Commandbutton.

Lets say.

Clicking Button 1 results in the use of the Selectcommand: SELECT * FROM MyTable (resulting in all attendees no matter what course)

Clicking Button 2 results in the use of the Selectcommand: SELECT * FROM MyTableWHERE Eventid = @.eventid

Thanks in advance,

Lx

|||

Hi,

Turned out to be quite simple:

<Grid>.SelectCommand =

"SELECT Blahblah" in the code for the Button worked fine.

Lx

No comments:

Post a Comment