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

Detail Table EditForm Template Values

1 Answer 76 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David Kingston
Top achievements
Rank 2
David Kingston asked on 28 Oct 2009, 09:30 PM

I've done quite a bit of searching and reading, and maybe I just don't get it.  Here's my problem.

I have a RadGrid with a nested Detail table.  The Detail Table is configured to use a Form Template.  To bind the values in the Form Template, I'm using markup that looks like this:

 
<asp:Label ID="lblID" runat="server" Text='<%# DataBinder.Eval( Container, "DataItem.ServerPowerID" ) %>' ></asp:Label> 
The form populates with data nicely and everything is good.  That form has buttons on it for update and insert:
<asp:Button ID="btnUpdate"  Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update"%>' runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PowerInsert" : "PowerUpdate" %>'/>  
<asp:Button ID="btnCancel" Text="Cancel" CausesValidation="false" runat="server" CommandName="Cancel"/> 
I'm catching the RadGrid_ItemCommand (and I have verified that it fires).  In other, non-nested grids, I've used code like this to populate a custom data object that updates the database:
if (e.CommandName == "PowerUpdate")  
            {  
                GridEditableItem editedItem = e.Item as GridEditableItem;  
                CMDB.ServerPower power = new CMDB.ServerPower(Convert.ToInt32((editedItem.FindControl("lblID"as Label).Text));  
                power.ServerID= (Convert.ToInt32((editedItem.FindControl("lblServerID"as Label).Text));  
                power.ServerPowerNameID = Convert.ToInt32((editedItem.FindControl("ddlServerPowerName"as DropDownList).SelectedValue);  
                power.ServerPowerCircuitID = Convert.ToInt32((editedItem.FindControl("ddlServerPowerCircuit"as DropDownList).SelectedValue);  
                power.ServerPowerNotes = (editedItem.FindControl("tbNotes"as TextBox).Text;  
                power.Save(User.Identity.Name.ToString());  
                ServerRadGrid.Rebind();  
            } 

The problem is that editedItem is continually null.  Since this code works on non-nested grids with success, I assume that I'm not referencing the nested grid's editable item correctly.  Can someone either point me to a post/tutorial that shows me what the correct way to reference these controls on the nested grid are, or better yet just show me the light with this example? 

1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 1
answered on 29 Oct 2009, 11:24 AM
Hi,

To identify the nested  table to which the current row belongs/is bound  you can use the Name property .You can set the Name property in the grid definition
C#
if (e.CommandName == "PowerUpdate" && e.Item.OwnerTableView.Name == "DetailTableName")   
            {   
 
              //Perform Update 
 
            }

Thanks
Shinu.



Tags
Grid
Asked by
David Kingston
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 1
Share this question
or