How to change data in grid after you change the SQL select for the data adapter

T

tom c

I have an ASP.net webform with a datagrid on it.

I can change the SQL select statement for the grid in code by putting
a statement like this in the first line of Page_Load
OleDbDataAdapter1.SelectCommand.CommandText = "SELECT * from table
where ... "

The rest of the code in Sub Page_Load is

OleDbDataAdapter1.Fill(DsCategories1)
If Not IsPostBack Then
DataGrid1.DataBind()
End If

This works fine on the initial load of the the webform. If I want to
change the SQL command to load different data into the grid after the
form is loaded, and do that with a cmdButton, what code to I put under
the cmdButton to reload the webform or grid with the new sql select?
 
P

PeterKellner

I have an ASP.net webform with a datagrid on it.

I can change the SQL select statement for the grid in code by putting
a statement like this in the first line of Page_Load
OleDbDataAdapter1.SelectCommand.CommandText = "SELECT * from table
where ... "

The rest of the code in Sub Page_Load is

OleDbDataAdapter1.Fill(DsCategories1)
If Not IsPostBack Then
DataGrid1.DataBind()
End If

This works fine on the initial load of the the webform. If I want to
change the SQL command to load different data into the grid after the
form is loaded, and do that with a cmdButton, what code to I put under
the cmdButton to reload the webform or grid with the new sql select?

You would call DataBind() on your datagrid. This rexecutes the get
code in your bound datasource.
Peter Kellner
http://peterkellner.net
 

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

Staff online

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top