DataGrid control with checkbox template column

R

Ryan Lafferty

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
 
G

Grant Merwitz

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?
 
R

Ryan Lafferty

Thank you Grant, worked like a charm! Wasn't bad at all.


BTW:
e.Item.ItemTemplate (c#) = e.Item.ItemType (VB)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top