473,320 Members | 1,950 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.

DataGrid, Sorting & Checkboxes

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
Nov 19 '05 #1
1 1147
Correction:

grdResults.Datasource = dv //Not "dt"
"David McCormick" wrote:
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

Nov 19 '05 #2

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

Similar topics

2
by: DelphiBlue | last post by:
I have a Nested Datagrid that is using a data relations to tie the parent child datagrids together. All is working well with the display but I am having some issues trying to sort the child...
1
by: Sargas Atum | last post by:
Hi all, 1. I have a problem with cell selection in a table in a DataGrid. I dont want that anybody writes in the cells. That was not a problem I changed them to "read only", but if I am going...
2
by: Raj | last post by:
Hi, When we are sorting the DataGrid Boolean column the grid is becoming redcross. I have my own PPMIPDataGridBoolColumn class inherited from System.Windows.Forms.DataGridBoolColumn. In this...
2
by: ddaniel | last post by:
I have read many posts and seen many papers on the different techniques for sort and filtering datagrids. Many do re-queries against the dB ala Fritz Onion. I am trying to leverage the Dataview....
2
by: Mortar | last post by:
i have a datagrid with 2 columns. the 1st column contains an id which will be used by the database for the selected checkbox records. the 2nd column is a template column containing a server...
2
by: pmanno | last post by:
If I have a page with a DataGrid that is bound to a DataTable that is populated by a query to a database and I want to enable sorting and paging, do I have to add the DataTable to the cache or will...
3
by: elziko | last post by:
I have a DataTable bound to a DataGrid. When a user clicks on a row on the DataGrid I use: MyDataTable.Rows(MyDatagrid.CurrentRowIndex).Item(0) to do some work with the value in the first cell...
7
by: rn5a | last post by:
The first column of a DataGrid has a CheckBox for all the rows. I want that when users check a CheckBox, the BackColor of that entire row in the DataGrid should change to a different color. To...
0
by: Scott | last post by:
Hello all and thanks in advance for any help you may be able to offer me. I am quite new to asp.net and am trying to work with a datagrid but am having some problems with it. Here's the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.