Click here to Skip to main content
12,947,948 members (47,603 online)
Click here to Skip to main content
Add your own
alternative version


39 bookmarked
Posted 19 Nov 2003

Changing a column in multiple DataGrid rows using checkboxes

, 19 Nov 2003
Rate this:
Please Sign up or sign in to vote.
This article demonstrates how to apply a dropdownlist value to multiple rows in a DataGrid.

Sample Image - chk.gif


This article will demonstrate how to change the value of a DataGrid column in multiple rows using checkboxes. This is a very common problem and it's easily implementable, so without much ado, let's get to the point.

Before I start, though, I'll put forward one assumption I make in this article, make sure your code meets the underlying requirement, otherwise you'll have to do some extra work.

I'll assume that the data bound to the grid is also editable through some object in your code (in other words, DataGrid columns are properties of one object) and you have an update routine for this object. For example, in our case, the object we're using is PurchaseOrder, and the column (property) is ApprovalStatus.

First off, let's start with a simple bind routine. The getApproverPOs function simply returns a DataTable object, you can replace it with your own DataTable.

Sub BindGrid()
    dgPO.DataSource = PurchaseOrder.getApproverPOs
End Sub

In our example, we have a dropdown named lstStatus and a button named btnApply.

The Iterate routine which follows next will loop through each row and see if the checkbox (named chk) in the DataGrid's first template column is checked, if so, it will load PurchaseOrder, set a new ApprovalStatus, and update the changes.

Public Sub Iterate() 
 Dim DGItem As DataGridItem
 Dim chkSel As System.Web.UI.WebControls.CheckBox
 Dim po As PurchaseOrder
 For Each DGItem In dgPO.Items
  chkSel = DGItem.FindControl("chk")
  If chkSel.Checked Then
    po = PurchaseOrder.getPO(DGItem.Cells(1).Text) 'pass the po number to get
    po.ApprovalStatus = lstStatus.SelectedItem.Value
    'send an email to original PO poster
  End If
End Sub

And finally, we need an event handler for our button which will point to the Sub above. We use Response.Redirect in the end to refresh the checkboxes, as well as the ApprovalStatus column.

Private Sub btnApply_Click(ByVal sender _
  As System.Object, ByVal e As System.EventArgs) _
  Handles btnApply.Click
End Sub

That's all there is! Hope this was helpful.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Mesrop Simonian
Web Developer
United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
manoj kumar choubey7-Feb-12 19:29
membermanoj kumar choubey7-Feb-12 19:29 
GeneralUsing checkbox in autogenerated datagrid Pin
ashasprabhu20-Jun-07 21:12
memberashasprabhu20-Jun-07 21:12 
QuestionValue in TextBox should be changed to required formate Pin
kishore19@hotmail.com28-Dec-06 6:45
memberkishore19@hotmail.com28-Dec-06 6:45 
QuestionHow to add the multiple edit in this auto generated script Pin
Anonymous4-Sep-05 16:20
sussAnonymous4-Sep-05 16:20 
GeneralMultiple checkboxes selection. PLEASE HELP. Pin
misssBlur3-Apr-04 19:56
membermisssBlur3-Apr-04 19:56 
GeneralChecking if an item is checked before post back Pin
Esterbarn27-Nov-03 22:15
sussEsterbarn27-Nov-03 22:15 
GeneralRe: Checking if an item is checked before post back Pin
Mesrop Simonian2-Dec-03 6:52
memberMesrop Simonian2-Dec-03 6:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170518.1 | Last Updated 20 Nov 2003
Article Copyright 2003 by Mesrop Simonian
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid