473,320 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Change selectcommand of accessdatasource in code and sorting or paging

Hi,

I know I am not the only one struggling with the following, but so far
I have not seen a solution.

Problem:
I have an asp.net 2.0 web page with a gridview which is bound to an
accessdatasource. In my code-behind I want to be able to set the
selectcommand of the datasource to a specific SQL string based on a
user's input to retrieve only certain records.

This works fine when I hit the search button. BUT, as soon as I start
paging or sorting (gridview's default), the accessdatasource seems to
revert back to the initial select command "SELECT * FROM tblProduct"
and all records are shown again.

I know that I could maintain state for the selectcommand using session
variables, but I would like to see a cleaner solution.

My code in aspx:
<asp:AccessDataSource ID="AccessDataSource1"
DataFile="~/App_Data/product.mdb" SelectCommand="SELECT * FROM
tblProduct" runat="server" DataSourceMode=DataSet />

My code in code-behind:
AccessDataSource1.SelectCommand = "SELECT * FROM tblProduct WHERE
[brand]='" & txtBrandCustom.Text & "'"

Hopefully, anyone out there will have a solution for me!

Regards,

Mark

Dec 2 '06 #1
0 3398

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dave S | last post by:
Hi, I'm using a datagrid to display contents of a dataset and I've set the datagrid to allow paging and sorting. Rather than re-retrieve from the DB, I store the original dataset in a Session...
1
by: Guoqi Zheng | last post by:
Sir, The default paging of datagrid is somehow use too much resource, so I am using Stored procedure for the paging. You can find my Stored procedure at the end of this message. It works...
3
by: needin4mation | last post by:
Is the framework going to change so that on sorting it will have some way of letting you sort two ways, asc or desc? Is the framework's paging going to change so that it does not bring back the...
1
by: K B | last post by:
Hi. I have a gridview with sqldatasource, etc. For the grid, I also have a search textbox. If the user needs to filter the records, I want to dynamically adjust the SELECT statement for the...
2
by: bruno | last post by:
I'm trying to dynamicaly change Where conditions in a Datagrid without success. The aspx form has some input fields, used to build the search, plus a final SEARCH button. In the click event I build...
3
by: Ashton | last post by:
Hello, I have a GridView; once the page is loaded I can sort it just fine, I can sort it as many times as I would like, I can sort any of the columns. After clicking on Search and the...
4
by: djohnson | last post by:
Hello, I'm wondering why a variable in my selectcommand is not working. In Page_Load I have this: String current_user = User.Identity.Name; Response.Write(current_user); // verified the...
1
by: Dave | last post by:
Hello, I'm wondering why a variable in my selectcommand is not working. In Page_Load I have this: String current_user = User.Identity.Name; Response.Write(current_user); // verified the...
1
by: John A Grandy | last post by:
In regard to a GridView that must support searching, filtering, sorting, and paging ... There is a tradeoff in performing the sorting and paging in the database versus to creating a CLR sort...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.