use same DetailsView for multiple purposes?

G

Guest

In some cases I would like to allow a user to select a row from a GridView to
update in another page using a DetailsView form (passing the key in
QueryString).

In other cases I would like to use the same DetailsView form to allow
general edit/insert/delete functions with Paging=true.

I can't figure out how to change the select statement from one case to the
other, e.g. if I have an SqlDataSource with:

SelectCommand="SELECT [VanId], ... [Active] FROM [Vans] WHERE
(VanId=@VanId)"
<SelectParameters>
<asp:QueryStringParameter QueryStringField="pk" Name="VanId" ... />
</SelectParameters>

How do I change the SelectCommand on the fly, e.g. when I want general
editing I would like to use:
SelectCommand="SELECT [VanId], ... [Active] FROM [Vans]"
and not use WHERE clause.

Any suggestions would be appreciated.
 
G

Guest

You could set the SQL statement without the where clause and then use the
SQLDataSource.FilterExpression property when you want to filter the results.
if you wanted to simulate.

SELECT field1,field2 from table where field1 = value

you would set the SelectCommand property to

SQLDataSource.SelectCommand="SELECT field1,field2 from table ";

then set

SQLDataSource.FilterExpression="field1 = value";

when you wanted to simulate the where clause.

To supply paramaters to the filter expression you can use
SQLDataSource.FilterParameters
 
G

Guest

Thanks that worked. I took it a step further, using FindControl to locate
the SqlDataSource and actually change the SelectCommnand string. That way
only the rows I want are selected instead of selecting all the rows and then
applying a filter.

Thanks again.

Michael

clickon said:
You could set the SQL statement without the where clause and then use the
SQLDataSource.FilterExpression property when you want to filter the results.
if you wanted to simulate.

SELECT field1,field2 from table where field1 = value

you would set the SelectCommand property to

SQLDataSource.SelectCommand="SELECT field1,field2 from table ";

then set

SQLDataSource.FilterExpression="field1 = value";

when you wanted to simulate the where clause.

To supply paramaters to the filter expression you can use
SQLDataSource.FilterParameters



Dabbler said:
In some cases I would like to allow a user to select a row from a GridView to
update in another page using a DetailsView form (passing the key in
QueryString).

In other cases I would like to use the same DetailsView form to allow
general edit/insert/delete functions with Paging=true.

I can't figure out how to change the select statement from one case to the
other, e.g. if I have an SqlDataSource with:

SelectCommand="SELECT [VanId], ... [Active] FROM [Vans] WHERE
(VanId=@VanId)"
<SelectParameters>
<asp:QueryStringParameter QueryStringField="pk" Name="VanId" ... />
</SelectParameters>

How do I change the SelectCommand on the fly, e.g. when I want general
editing I would like to use:
SelectCommand="SELECT [VanId], ... [Active] FROM [Vans]"
and not use WHERE clause.

Any suggestions would be appreciated.
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top