The ItemDataBound is firing once because nothing is being bound in your
Header so it just fires without problem. That's why you are getting your
error on the first item in the datagrid that is actually data bound.
I had a similar issue that I had to address with a datagrid with several
[quoted text, click to view] items that needed to be inaccessible to the user, so what I did was I wrote
a small function that I put in my code behind like the following.
protected function IsNullValue(val as Object) as Boolean
if val.Value = DBNull.Value then
return false
else
return true
end if
end function
Sorry if the function is off a bit, I'm a bit rusty on my VB.Net. Anyway
what I did then was on the actual checkbox control, I bound the Enabled
value to
IsNullValue(DataBinder.Eval(Container.DataItem, "yourcolumn")
If the value passed into the function is a null value, then it returns
false, disabling the checkbox control, if there is a value, then the
checkbox is enabled. You could also do so for the checked property.
Hope this gets you started,
Darren Kopp
[quoted text, click to view] "SRuby" <xruby10@devdex.com> wrote in message
news:ugA2EsxwFHA.2932@TK2MSFTNGP10.phx.gbl...
>
>
> Hi,
>
> I try to disable /hide datagrid checkbox when the value of the field is
> null,
>
> I have try to put some code in ItemDataBound to invisible the checkbox
> when databind() fired
>
> Here's the codein ItemDataBound event
>
> If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
> ListItemType.AlternatingItem Or _
> e.Item.ItemType = ListItemType.EditItem Or e.Item.ItemType =
> ListItemType.SelectedItem Then
> Dim drv As DataRowView = CType(e.Item.DataItem, DataRowView)
> If drv("isexist").ToString = "" Then
> e.Item.Cells(2).Visible = False
> end if
> end if
>
> When I debug the program, the ItemDataBound was triggered once when the
> ListItemType = Header, after that, the error raises
> Cast from type 'DBNull' to type 'Boolean' is not valid.
>
> Why the OnItemDataBound only triggered once?
>
> thank
>
> Ruby
>
> *** Sent via Developersdex
http://www.developersdex.com ***