R
Rob Wire
How do you check if CType(e.Item.DataItem, DataRowView) is
DBNULL?
I have a Datagrid with Edit,Update, and Insert buttons to
a SQL data table. During an update, a drop down list is
used for one of the fields which defaults to current value
in a row.
Private Sub DataGrid1_ItemDataBound(ByVal sender As
Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound
If e.Item.ItemType = ListItemType.EditItem Then
Dim drv As DataRowView = CType
(e.Item.DataItem, DataRowView)
Dim currentAttachType As String
currentAttachType = CType(drv("ATTACH_TYPE"),
String)
Dim ddl As DropDownList
ddl = CType(e.Item.FindControl
("DropDownList1"), DropDownList)
ddl.SelectedIndex = ddl.Items.IndexOf
(ddl.Items.FindByText(currentAttachType))
End If
End Sub
Insert fails with an error "Cast from type 'DBNull' to
type 'String' is not valid" if this function is used.
Insert button on click uses the regular update function as
well.
I think an if statement on the drv("ATTACH_TYPE") to check
if it is a DBNULL or not might fix it. How might you do
this?
Any suggestions?
Thank you,
Rob Wire
DBNULL?
I have a Datagrid with Edit,Update, and Insert buttons to
a SQL data table. During an update, a drop down list is
used for one of the fields which defaults to current value
in a row.
Private Sub DataGrid1_ItemDataBound(ByVal sender As
Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound
If e.Item.ItemType = ListItemType.EditItem Then
Dim drv As DataRowView = CType
(e.Item.DataItem, DataRowView)
Dim currentAttachType As String
currentAttachType = CType(drv("ATTACH_TYPE"),
String)
Dim ddl As DropDownList
ddl = CType(e.Item.FindControl
("DropDownList1"), DropDownList)
ddl.SelectedIndex = ddl.Items.IndexOf
(ddl.Items.FindByText(currentAttachType))
End If
End Sub
Insert fails with an error "Cast from type 'DBNull' to
type 'String' is not valid" if this function is used.
Insert button on click uses the regular update function as
well.
I think an if statement on the drv("ATTACH_TYPE") to check
if it is a DBNULL or not might fix it. How might you do
this?
Any suggestions?
Thank you,
Rob Wire