473,624 Members | 2,248 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
DataGridSortCom mandEventArgs) Handles grdResults.Sort Command
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.SortExpressio n

grdResults.Data Source = dt
grdResults.Data Bind()
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.I mageClickEventA rgs) Handles btnSubmit.Click
With grdResults
For Each DGItem In .Items
Dim checkBox As CheckBox =
CType(DGItem.Ce lls(0).Controls (1), CheckBox)
If checkBox.Checke d = True Then
' Do something here
End If
Next
End With
End Sub

Any help would be great!

Thanks,
Dave
Nov 19 '05 #1
1 1159
Correction:

grdResults.Data source = 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
DataGridSortCom mandEventArgs) Handles grdResults.Sort Command
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.SortExpressio n

grdResults.Data Source = dt
grdResults.Data Bind()
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.I mageClickEventA rgs) Handles btnSubmit.Click
With grdResults
For Each DGItem In .Items
Dim checkBox As CheckBox =
CType(DGItem.Ce lls(0).Controls (1), CheckBox)
If checkBox.Checke d = 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
945
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 datagrid. HTML Datagrid1 TemplateColumn Table Header information Detail Information
1
2056
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 to scroll the table up and down or from right to the left the content of the active cell will be selected as if for copy/paste. How can I deactivate such a behaviour?
2
2350
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 inherited class I have one DataGridValueChangedEventHandler event handler. I am overriding Edit() to know the current state of the cell. I am overriding Paint() to know the if the user has been editing the cell. I am also overriding the Commit() to
2
1604
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. The following control simply responds to a sort request and/or a pageing reqeust with an empty table (header only). Any ideas ? Code behind : namespace OakTree.data {
2
2453
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 checkbox control. where i'm at: i can retrieve a count of the selected checkboxes, but don't know how to get the related id's (in the 1st column).
2
1349
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 the viewstate hold the contents of the DataTable? Basically, I want to avoid hitting the database wherever I can. It seems that the DataTable has to be cached and the DataGrid re-bound, or the DataTable has to be re-populated from the...
3
3373
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 for the currently selected row. However, when I delete a row (using the delete key oin the grid) and try and do the above on the row that has now taken the deleed roe's position in the grid I get the following exception:
7
2505
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 implement this, if I am not mistaken, I HAVE TO post the Form first i.e. set the AutoPostBack property of the CheckBox to True. Without posting the Form, I don't think the BackColor of the checked row can be changed using ASP.NET, isn't it? Of...
0
2578
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 problem... My datagrid displays 2 columns of checkboxes and allows the user to select the check boxes and sort the datagrid. My first problem, if
0
8233
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8675
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8474
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7158
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5561
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2604
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1784
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.