Datagrids, Sorting & Checkboxes

  • Thread starter David McCormick
  • Start date
D

David McCormick

I have been scouring the message boards before I posted this question hoping
to find an answer regarding datagrids and their behaviour after a sort
command has been invoked.

What I am trying to accomplish is this:
I have a datagrid that has several columns directly bound from data table
and on each row of the grid, the user has the ability to select that person
displayed. When the user does NOT sort this grid their selections are
correct after they submit their request, but as soon as they sort the grid
and select individuals, they receive the individuals in the position before
they sorted the grid. I am trying to ensure that the individual that is
being selected is really the individual that I am using moving forward.

Here is the code:

********* Grid Sorting *********
Public Sub grdResults_Sort(ByVal source As Object, ByVal e As
DataGridSortCommandEventArgs) Handles grdResults.SortCommand
Dim ds As New DataSet

ds = CType(Session("BorrowerList"), DataSet)

Dim dt As DataTable = ds.Tables(0)

Dim dv As DataView = New DataView(dt)

dv.Sort = e.SortExpression

grdResults.DataSource = dt
grdResults.DataBind()
End Sub

***** What I am doing to get the "selected items" out of the grid *****
Private Sub btnSubmit_Click(ByVal sender As Object, ByVal e As
System.Web.UI.ImageClickEventArgs) Handles btnSubmit.Click
With grdResults
For Each DGItem In .Items
Dim checkBox As CheckBox =
CType(DGItem.Cells(0).Controls(1), CheckBox)
If checkBox.Checked = True Then
' Do something here
End If
Next
End With
End Sub

Any help would be great!

Thanks,
Dave
 
R

R. Thomas, aka Xtreme.Net

What do you mean by this :
but as soon as they sort the grid
and select individuals, they receive the individuals in the position before
they sorted the grid. I am trying to ensure that the individual that is
being selected is really the individual that I am using moving forward.
R. Thomas
 
D

David McCormick

After the user sorts & selects the individuals via checkboxes in the data
grid and click the submit button, on post back the application thinks that
the items checked are the items prior to the sort command being executed.

From what I understand, the table in the dataview that is being used to bind
to the grid for sorting is actually still not sorted. Though, I am still not
sure of the best way of retrieving the correct items out of the grid.

In Windows Forms you can use the CurrencyManager to keep the data between
the datagrid and the datasource in synch.

Any input would be greatly appreciated! Thanks again!
 

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,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top