Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > DataGrid control with checkbox template column

Reply
Thread Tools

DataGrid control with checkbox template column

 
 
Ryan Lafferty
Guest
Posts: n/a
 
      08-08-2005
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!

 
Reply With Quote
 
 
 
 
Grant Merwitz
Guest
Posts: n/a
 
      08-08-2005
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!
>



 
Reply With Quote
 
 
 
 
Ryan Lafferty
Guest
Posts: n/a
 
      08-08-2005
Thank you Grant, worked like a charm! Wasn't bad at all.


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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create the checkbox template column dynamically in datagrid NEMA ASP .Net 0 06-05-2006 02:44 PM
CheckBox unchecked status detection in DataGrid Template Column Javier ASP .Net 2 12-12-2005 05:16 PM
DataGrid loses view state if first column is a template column. Ken Varn ASP .Net 1 08-19-2005 02:54 PM
how to know if a datagrid column is a template column? Dexter ASP .Net 1 01-18-2005 01:45 PM
Convert an MS Access Yes/No column to a checkbox column in C# datagrid Gregory Rampton ASP .Net Datagrid Control 0 08-06-2003 04:09 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57