Hi,
I have a grid with detail tables. When the user expands an entry in the parent table, the child table data gets populated via the DetailTableDataBind event. That's all working properly when things go right. I'm trying to implement something to address when the detail data retrieval fails.
I've tried setting Cancelled = true in the GridDetailTableBindEventArgs parameter, but that appears to do nothing.
What's even more strange is that if I don't set the value of DetailTableView.DataSource, or I set it to nothing, the value of DetailTableView.DataSource takes on the value of the parent item datasource. That produces an exception because the parent table doesn't have the columns specified in the detail table DataKeyNames property. If I clear the DataKeyNames, I can prevent the exception. But then the child grid shows the parent grid records.
The following is a sample DetailTableDataBind Event: What can I do to either prevent the parent item from opening, show an empty child item, etc?
Protected Sub rgGrid_DetailTableDataBind(sender As Object, e As GridDetailTableDataBindEventArgs) Handles rgErrorGrid.DetailTableDataBind
Select Case e.DetailTableView.Name
Case "DetailTableName"
Dim dataItem As GridDataItem = TryCast(e.DetailTableView.ParentItem, GridDataItem)
Dim KeyVal As Integer
Dim dt As DataTable = Nothing
If Integer.TryParse(dataItem.GetDataKeyValue("ID").ToString(), KeyVal) Then
dt = GetDetailTable(KeyVal)
End If
If dt Is Nothing Then
' What do I need to do here to either prevent the parent item from expanding, or show an empty grid...without throwing an exception?
e.DetailTableView.DataSource = Nothing
e.Canceled = True
Else
e.DetailTableView.DataSource = dt
End If
End Select
End Sub