Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

build/filter datagrid on client side

Status
Not open for further replies.

codecomm

Programmer
Joined
Feb 14, 2007
Messages
121
Location
US
We have a datagrid, v1.1, and it first shows data to the user based off a SPROC, and might be, for example, 20 rows.

What we'd like to do is allow the user to check a box on the last column, "include in filter", click a button, and only show the rows the users has clicked....i.e. now only 3 rows.

Can this be done client side w/o a database call?
 
If you want to do it client-side, then you would have to use a client-side language such as javascript to hide certain rows. I'd ask in the javascript forum on how to hide rows from a HTML table if you can't fins how to do this yourself.


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
If there's another way, I'm open, but I just figured this was the only way....any other ideas/thoughts?
 
If you don't want to hit the DB again, you could get the ID value on each row that is checked. Then you remove thoses rows, based on ID, from the underlying datatable or a copy of it, then rebind to the grid. This is assuming your are using a dataset or datatable.
 
jbenson001,

Seems like you should be able to use the Datagrid's Dataset from a button click event handler after the page has loaded and the datagrid has been built via this dataset...is that right?

Any hints are appreciated. If we just call the dataset, and try to build the grid again, no data is returned. Is that because we're pointing to the dataset object itself, but no underlying data?

here's some code we're trying:
Try
For Each dgI As DataGridItem In DG.Items
'get the checkbox
Dim chkSelected As CheckBox = DirectCast(dgI.FindControl("chkbxHide"), CheckBox)
'If the checkbox is checked
If chkSelected.Checked Then
Dim removeitem As Integer = dgI.ItemIndex
'dt.Rows.RemoveAt(0)
DS.Tables(0).Rows(removeitem).BeginEdit()
DS.Tables(0).Rows(removeitem).Delete()
DS.Tables(0).Rows(removeitem).EndEdit()
DS.Tables(0).Rows(removeitem).AcceptChanges()
DG.DataBind()
End If
Next

Catch ex As Exception
lblStatus.Text = "Error: " & ex.Message
Finally

End Try
 
You will need to persist the DataTable somewhere (ViewState, Session, Cache etc) and bind to that each time (after you've made the relevant modifications to it).


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
So, basically, if we simply use the button click event handler, and don't put the Dataset into ViewState, then when we try to bind the datagrid to the Dataset on a button click, it's blank b/c ...well...it's stateless and we haven't held the dataset into anything like ViewState, Cache, SessionState, etc...right?
 
Yes, kind of. The data will be persisted for the DataGrid so that it can be rendered on each load of the page, however the DataTable itself isn't persisted. As you are wanting to persist a DataTable, manipulate it before rebind the DataGrid, you will have to store it somewhere.


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top