Groups | Blog | Home
all groups > asp.net datagrid control > august 2005 >

asp.net datagrid control : Adding a select column...


Paul Mason
8/31/2005 12:00:00 AM

Hi folks,

I am aiming to create a "select" column that is unbound on datagrid whose
other columns are all data bound. The idea is to let the user select items
to be printed etc.

The problem I have arises when I want to find out which rows are selected.
The following code is a tester that puts values into a string to be
displayed, but it's representative.

Dim chk As CheckBox

Dim itm As DataGridItem

Dim str As String

For Each itm In Me.dgVialList.Items

chk = CType(itm.Cells(0).Controls(0), CheckBox)

If chk.Checked Then

str += itm.Cells(1).Text & ", "

End If

Next

The problem occurs at chk = CType(itm.Cells(0).Controls(0), CheckBox) where
it says that it cannot cast the item as a checkbox. This collection is base
0?? I have only one template control (ItemTemplate).

Any ideas?

Cheers...P






Paul Mason
8/31/2005 12:00:00 AM

Many apologies folks...I needed to refer to itm.Cells(0).Controls(1). I'm
not sure why this should be so, but I've got it working now.

Cheers...P


[quoted text, click to view]

Elton Wang
8/31/2005 1:54:08 PM
Hi Paul,

Actually, the better way is:



chk = CType(itm.FindControl(checkbox_ID), CheckBox)



So you don't need to worry about it's in Controls(0) or Controls(1).



HTH





[quoted text, click to view]

AddThis Social Bookmark Button