hidng and showing rows on a datagrid

  • Thread starter Thread starter John Smith
  • Start date Start date
J

John Smith

Hello all,

I have a datagrid that is bound to a database table using the designer. What
I need to do is show or hide data on the grid via a button.

e.g. "Show completed tasks" and "Hide Completed Tasks"

How wold I go about doing this? Is there a function for the datagrid to be
able to do this or would I have to connec to the db again and bind to a new
query?


cheers
 
I don't think you could do this with a table bound to the designer. However,
if you used a Dataview, you could set and reset the filter to mimic this
action. Alternatively, you could make a separate trip to the server for the
data, which may or may not be more productive than a single trip to load
everything up and then filter it. Try it both ways.
 
ok here is my button_click method:

Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB
Services=-4; Data Source=" & Server.MapPath("/database/database.mdb")
Dim dbConnection As System.Data.IDbConnection = New
System.Data.OleDb.OleDbConnection(connectionString)

Dim queryString As String = "SELECT
[Special_Cleaning_Tasks].[Special_Task_id], [Special_Cleaning_Tasks].[Spec"
& _
"ial_Task_Description], [Special_Cleaning_Tasks].[Task_Status],
[Special_Cleaning" & _
"_Tasks].[Date_Logged] FROM [Special_Cleaning_Tasks] WHERE
([Special_Cleaning_Tas" & _
"ks].[Task_Status] = ""Completed"")"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dataAdapter As System.Data.IDbDataAdapter = New
System.Data.OleDb.OleDbDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dsCompleted As System.Data.DataSet = New System.Data.DataSet
dataAdapter.Fill(dsCompleted)
dgSpecial.DataSource = dsCompleted
dgSpecial.DataMember = "Special_Cleaning_Tasks"
dgSpecial.DataBind()

The original data is bound using the page_load:

oledbdataadapter.fill(dsSpecial1)
dgSpecial.databind()


If i click the button will the dg automatically go back to being boudn to
the dataset in the page_load?



cheers
 
IS there someway to just do it dynamically without a postback?


John Smith said:
ok here is my button_click method:

Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB
Services=-4; Data Source=" & Server.MapPath("/database/database.mdb")
Dim dbConnection As System.Data.IDbConnection = New
System.Data.OleDb.OleDbConnection(connectionString)

Dim queryString As String = "SELECT
[Special_Cleaning_Tasks].[Special_Task_id],
[Special_Cleaning_Tasks].[Spec" & _
"ial_Task_Description], [Special_Cleaning_Tasks].[Task_Status],
[Special_Cleaning" & _
"_Tasks].[Date_Logged] FROM [Special_Cleaning_Tasks] WHERE
([Special_Cleaning_Tas" & _
"ks].[Task_Status] = ""Completed"")"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dataAdapter As System.Data.IDbDataAdapter = New
System.Data.OleDb.OleDbDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dsCompleted As System.Data.DataSet = New System.Data.DataSet
dataAdapter.Fill(dsCompleted)
dgSpecial.DataSource = dsCompleted
dgSpecial.DataMember = "Special_Cleaning_Tasks"
dgSpecial.DataBind()

The original data is bound using the page_load:

oledbdataadapter.fill(dsSpecial1)
dgSpecial.databind()


If i click the button will the dg automatically go back to being boudn to
the dataset in the page_load?



cheers















Earl said:
I don't think you could do this with a table bound to the designer.
However, if you used a Dataview, you could set and reset the filter to
mimic this action. Alternatively, you could make a separate trip to the
server for the data, which may or may not be more productive than a single
trip to load everything up and then filter it. Try it both ways.
 
Back
Top