Showing posts with label gridview. Show all posts
Showing posts with label gridview. Show all posts

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

Sunday, March 11, 2012

Changing SelectMethod in SQLDataSource

I have a gridview bound to an ObjectDataSource, which is a dataset populated by SQL queries. The gridview works with the default SelectMethod configured in the ObjectDataSource. I would like to be able to change the SelectMethod based on user input, which would call a different query. I have one textbox for input and several buttons to pick the type of filter.

My gridview populates on with the default selectmethod if I create a button that does nothing but a postback. My other buttons run the following codes which returns nothing. Any ideas what I'm doing wrong?

If

e.CommandArgument ="Last_Name"Then

EmployeeData.SelectMethod =

"GetDataByLastName"EndIfIf e.CommandArgument ="First_Name"Then

EmployeeData.SelectMethod =

"GetDataByFirstName"EndIf

gvPhoto.DataSourceID = EmployeeData.ID

gvPhoto.DataBind()

Thanks.

Lisa

Call EmployeeData.Databind() before the dvPhoto.DataBind()

Hope this help