PC Review


Reply
Thread Tools Rate Thread

DataGrid control with checkbox template column

 
 
Ryan Lafferty
Guest
Posts: n/a
 
      8th Aug 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
 
      8th Aug 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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
 
      8th Aug 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
Rate This Thread
Rate This Thread:

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 Microsoft ASP .NET 0 5th Jun 2006 03:44 PM
DataGrid & Checkbox Template Columns JP Microsoft ADO .NET 0 13th Feb 2006 02:16 PM
CheckBox unchecked status detection in DataGrid Template Column Javier Microsoft ASP .NET 2 12th Dec 2005 05:16 PM
CheckBox template in asp.net datagrid Bennett F. Dill Microsoft C# .NET 0 26th Mar 2004 04:08 PM
How to Bind a DropDownList control to a DataGrid in Template Column Jeff Petter Microsoft ADO .NET 1 5th Oct 2003 07:25 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:59 AM.