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

[Solved] Advice on Best Practice

1 Answer 132 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jaco de Wet
Top achievements
Rank 1
Jaco de Wet asked on 19 Jan 2010, 12:24 AM
I'm looking for some advice on the best practice to achieve something:

We have a hierarchical grid:
(category) RadGrid with MasterTableView
(metric) which has a DetailTable (GridTableView)
(alarms) which has a DetailTable (GridTableView)
which has an EditFormSettings (template) - FormTemplate
which shows a custom control to edit the alarm
(either a new alarm or amend existing alarm)
(custom control is loaded from a placeholder in the FormTemplate - probably not best?)

The structure is working well, and we can drill down correctly through the hierarchy.  My question is (and where I'd like some advice) - the custom control (lets call it the AlarmEditor) needs to know information about the hierarchy that has been traversed to reach it.  How is it best to pass and persist this information?

At the moment the AlarmEditor is created in the Load event of the Placeholder inside the FormTemplate -- I'm not totally sure this is necessary.  Additionally i've hooked into the ItemCommand of the Alarms detail table to attempt to capture the key information I need -- I can get it at this point, but how do I forward it to the AlarmEditor which hasn't been created at this point?

I would be very grateful if you could offer suggestions on best practice to achieve this goal.  At the moment i've tried to pass minimal key information down (with limited success), ideally I'd like to pass the DataItem down, or a more structured object.

Thankyou.

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 19 Jan 2010, 10:51 AM
Hello Jaco,

You can create the controls dynamically in the ItemCreated event. This way it will persist on every postback.
CS:
 
    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    { 
        if(e.Item is GridEditableItem && e.Item.IsInEditMode && e.Item.OwnerTableView.Name == "GridTableView1"
        { 
            GridEditableItem editItem = (GridEditableItem)e.Item; 
 
            TextBox textbox = new TextBox(); 
            textbox.ID = "editTextBox1"
            PlaceHolder ph = (PlaceHolder)editItem.FindControl("PlaceHolder1"); 
            ph.Controls.Add(textbox); 
 
            TextBox textbox1 = new TextBox(); 
            textbox1.ID = "editTextBox2"
            ph.Controls.Add(textbox1); 
        } 
    } 

You can access the parent tables in the hierarchy on clicking the edit of the child table using the following code snippet.
CS:
 
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridEditableItem && e.Item.IsInEditMode && e.Item.OwnerTableView.Name == "GridTableView1"
        { 
            GridEditableItem editItem = (GridEditableItem)e.Item; 
            TextBox textbox = (TextBox)editItem.Cells[2].FindControl("editTextBox1"); 
            GridDataItem item = (GridDataItem)editItem.OwnerTableView.ParentItem;// Access the immediate parent's tables value 
            string str = item["OrderID"].Text; 
            textbox.Text = str; 
 
            TextBox textbox1 = (TextBox)editItem.Cells[2].FindControl("editTextBox2"); 
            GridDataItem item1 = (GridDataItem)editItem.OwnerTableView.ParentItem.OwnerTableView.ParentItem; // Access the mastertable column value 
            string str1 = item1["ContactName"].Text; 
            textbox1.Text = str1; 
        } 
    } 

Thanks,
Shinu.
Tags
Grid
Asked by
Jaco de Wet
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or