Click to See Complete Forum and Search --> : DataGrid(WebForm)


Vic
01-10-2002, 12:44 PM
Hi
I have a question about DataGrid server control. I insert CheckBox in template
column of DataGrid. Please give me a hand how I can get access to this CheckBox
from code behind.
Appreciate any help. Thanks in advance.

Vic

Ian Lowe
01-10-2002, 05:57 PM
Hi, Vic,

> I have a question about DataGrid server control. I insert CheckBox in
template
> column of DataGrid. Please give me a hand how I can get access to this
CheckBox
> from code behind.
> Appreciate any help. Thanks in advance.

To access controls embeded in template columns, you'll want to handle the
DataGrid's ItemCreated or ItemDataBound events. The EventArgs parameter in
this event has an Item property which provides a reference to the row in the
DataGrid that was either just created or bound. Reference the column and the
control index to get to your checkbox.

For example, in an aspx page,

' WARNING: Air code

Sub dg_bind(sender As Object, e As DataGridItemEventArgs)
' Assume that the check box is in the 3rd column
' Assume that the check box is the
' first (or only) control in the column
Dim chk As System.Web.UI.WebControls.CheckBox
chk = e.Item.Cells(2).Controls(0)
' Do whatever you want witht the CheckBox.
End Sub

Hope this helps,

Ian.