473,394 Members | 1,751 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

DataGrid control with checkbox template column

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!

Nov 19 '05 #1
2 2472
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" <ry***********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr 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!

Nov 19 '05 #2
Thank you Grant, worked like a charm! Wasn't bad at all.
BTW:
e.Item.ItemTemplate (c#) = e.Item.ItemType (VB)

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Randy | last post by:
Hello, I'm creating a table on the fly that is used by a datagrid. I'm also creating a tableStyle that is used for the datagrid to make it look like I want. I'm using the DataGridBoolColumn to...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
5
by: Gene McCrory | last post by:
Is it possible to have a CustomValidator against two controls in an EditItemTemplate on a DataGrid? Case: Have a business rule that states if ATextBox starts with "ACertainValue" then BTextBox...
0
by: mike | last post by:
Hi there: I've read an excellent "how to"-article by Microsoft (no. 306227) - partly cited cited at the end of this email). I have implemented the code related to the part "How to Add a...
6
by: jiangyh | last post by:
hi there: I have a datagrid in my web form that contain a templet column.And in this templet column have a checkbox web control.I will get the checkbox state in my serverside. My question is...
2
by: Mortar | last post by:
i have a datagrid with 2 columns. the 1st column contains an id which will be used by the database for the selected checkbox records. the 2nd column is a template column containing a server...
10
by: Jennyfer J Barco | last post by:
Hello, I have a datagrid that brings some information from a query. I need to have a checkbox in each row so the user can select the rows he wants to reprint. Is it possible to have a checkbox...
2
by: Javier | last post by:
Hi Everyone, I have a dynamic checkbox in a datagrid that uses the ITemplate interface and has the checkchanged event wired up. When the checkbox is checked, the event event handler that...
0
by: dotnet dude | last post by:
I am creating a DataGrid control (ASP.NET 1.) with few bound columns and one template column in which i want to display CheckBox. So for each row in datagrid some databound fields and a checkbox...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.