ASP.NET - Use a checkbox to change the results of a SqlDataSource?

Really depends on your data access, if you have made a datasource on page, then you'll have two and the code will change which data source you have. If it is using the old ado.net then you will have two commands that run in seperate methods that get the sql query, and a similar thing will work for linq. Let me know how you bind to the grid and I will give you an example.

Up vote 0 down vote favorite share g+ share fb share tw.

I'm using Visual Web Developer 2010 Express. This is my first attempt at creating a . NET page.

I have a Gridview on a page that displays the results of a GridQuery. This works. I have a checkbox control (cb_Filter) on the same page that if checked, should add to the where clause of the GridQuery, (where Column5 IS NULL).

How do I check the state of the check box so it will run the query with or without the "filter". Asp.net query parameters checkbox sqldatasource link|improve this question asked Feb 2 '11 at 21:09Patrick Beesley143 100% accept rate.

Hopefully I'm understanding your question, I connect to the database using a "ConnectionString". I don't see any reference to ado.net so I assume it is the former. – Patrick Beesley Feb 2 '11 at 21:18 @patrick in any case you need a connection string.

Do you drop a datasource control on to the form? What does your code look like that gets your data into the grid? – Daniel Casserly Feb 2 '11 at 21:23 " SelectCommand= "SELECT Column1, column2 FROM TABLE"> – Patrick Beesley Feb 2 '11 at 21:38 ok so you have a datasource control.

You need to create another of these, one with the where clause and one without and then in the code behind on the checkbox changed event(autopostback to true) give it a bit of if (check. Cheked) grid. Datasource = datasource1; else grid.

Datasource = datasource 2 – Daniel Casserly Feb 2 '11 at 21:41 My GridView is called GridView1; its datasourceID = GridQuery1. In which section does the conditional (if cb_filter. Checked THEN GridQuery1 ELSE GridQuery2) go?

– Patrick Beesley Feb 2 '11 at 22:10.

If you want the grid results to change dynamically, autopostback should be True for the checkbox. This will cause the page to reload when the value changes. Then, in your page load routine you do something like this: If cb_filter.

Checked Then 'set the checked datasource or SQL string here Else 'set the unchecked datasource or SQL string here End If.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions