This is a migrated thread and some comments may be shown as answers.

Issues with DetailTable Admin form

2 Answers 74 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 07 Jan 2011, 01:48 PM
Hi All,

I've been trying to figure this out for a while and not having much luck hence this posting.

I have a grid that has a subgrid for each row using detailtables, both levels are editable.  Because I have checkboxes in the admin form of each level I need to setup the value of any new rows in the InitInsert event and all of this works nicely.  

I have two issues now.  The fist issue is that I need to conditionally hide the checkbox (and potentially other fields) in the child level depending on a value in the parent level.  The second issue is that I want to have a checkbox present on the form which when ticked and the record is saved a new insert form opens up - thus saving the user from clicking a on the new item icon again.

Re the first issue I have the following in the ItemCommand event for the grid,

...
ElseIf e.CommandName = "InitInsertElement" Then
    e.Canceled = True
    Dim newValues As System.Collections.Specialized.ListDictionary = New System.Collections.Specialized.ListDictionary()
    newValues("IncludeInTotal") = True
    'IF THE CostType CELL IN THE PARENT ROW = UnitCost THEN HIDE THE uxIncludeInTotal CHECKBOX ON THIS INSERT FORM
 
    DirectCast(e.Item, Telerik.Web.UI.GridDataItem).ChildItem.NestedTableViews(0).InsertItem(newValues)
ElseIf .....

Re the second issue I have tried the following code to trigger the insert form to reopen but although the itemcommand is triggered the insert form does not load.  

If CType(editedItem.FindControl("uxAddNewAfterSave"), CheckBox).Checked Then
    Dim parentItem = CType(e.Item.OwnerTableView.ParentItem, Telerik.Web.UI.GridDataItem)
    parentItem.FireCommandEvent("InitInsertElement", String.Empty)
End If

Any help please?

Regards,

Jon

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 10 Jan 2011, 06:54 AM
Hello Jon,

In ItemdataBound event, you can show/hide the Checkbox. Sample code is given below.

VB.NET:
Protected Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs)
    If TypeOf e.Item Is GridEditFormInsertItem AndAlso e.Item.OwnerTableView.IsItemInserted AndAlso e.Item.OwnerTableView.Name = "DetailTableName" Then
        'Distinguish grid rows in hierarchy with Name of DetailTable
        Dim insertItem As GridEditFormInsertItem = DirectCast(e.Item, GridEditFormInsertItem)
        Dim checkbox As CheckBox = DirectCast(insertItem.FindControl("CheckBox1"), CheckBox)
        'your condition
        checkbox.Visible = False
    End If
End Sub

And for you second issue, try the following approach. In ItemCommand event save the row index and in Prerender event open the insert form for corrresponding Item using the row index..

Private rowindex As Integer = -1
 
Protected Sub RadGrid1_ItemCommand(sender As Object, e As GridCommandEventArgs)
    If e.CommandName = RadGrid.PerformInsertCommandName AndAlso e.Item.OwnerTableView.Name = "DetailTableName" Then
        Dim insertItem As GridEditFormInsertItem = DirectCast(e.Item, GridEditFormInsertItem)
        Dim checkbox As CheckBox = DirectCast(insertItem.FindControl("uxAddNewAfterSave"), CheckBox)
        If checkbox.Checked Then
            Dim parentItem As GridDataItem = DirectCast(e.Item.OwnerTableView.ParentItem, Telerik.Web.UI.GridDataItem)
            rowindex = parentItem.ItemIndex
 
        End If
    End If
End Sub
 
 
Protected Sub RadGrid1_PreRender(sender As Object, e As EventArgs)
    If rowindex > -1 Then
        Dim tableView As GridTableView = DirectCast(RadGrid1.Items(rowindex).ChildItem.NestedTableViews(0), GridTableView)
        tableView.IsItemInserted = True
        tableView.Rebind()
        rowindex = -1
    End If
End Sub


Thanks,
Princy.
0
Jon
Top achievements
Rank 1
answered on 10 Jan 2011, 12:42 PM
Many thanks Princy.

I managed to do the first one late Friday but the second one eluded me.  Great work around on it and it works a treat.  Slightly more tricky than I initialy realised as I have all levels expanded by default.  As such I got exceptions being thrown by the row not having any child items - took a couple of minutes to realise that I needed to reference the rows differently but got it done

Thanks again for you help!

Best Regards,

Jon
Tags
Grid
Asked by
Jon
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Jon
Top achievements
Rank 1
Share this question
or