yeah, had this problem
You have to ensure you're not in the Header or Footer template, otherwise
the checkbox won't exist.
I'm C#, so i'll put that code, then attempt the VB way
Place this around your code
if(e.Item.ItemTemplate != ListItemType.Header && e.Item.ItemTemplate !=
ListItemType.Footer)
{
//do your logic here
}
So in VB:
if e.Item.ItemTemplate <> ListItemType.Header AND e.Item.ItemTemplate <>
ListItemType.Footer then
'do your processing here
end if
That wasn't bad huh?
"Ryan Lafferty" <> wrote in message
news: oups.com...
> Hi,
>
> I have a DataGrid control with a checkbox template column, and want to
> make the checkbox "disappear" when the 3rd column of the DataGrid
> contains the string "number". Is what I am trying to do impossible?
>
> This is what I have so far, but cannot get the darn thing to work:
>
> ------------------------------------------
> Private Sub myDataGrid_ItemDataBound(ByVal sender As Object, ByVal e As
> System.Web.UI.WebControls.DataGridItemEventArgs) Handles
> myDataGrid.ItemDataBound
>
> Dim asdf As CheckBox
> asdf = CType(e.Item.FindControl("chk1"), CheckBox)
>
> If InStr(e.Item.Cells(3).Text, "Number") > 0 Then
> asdf.Visible = False
> Else
> asdf.Visible = True
> End If
> end Sub
> ------------------------------------------
>
> The code snippet above yields an "Object reference not set to an
> instance of an object." error. I am out of ideas....please help!
>
|