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

Prepopulate ID Field on Insert Form

2 Answers 82 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tom Edward
Top achievements
Rank 1
Tom Edward asked on 23 Aug 2010, 02:05 AM
Hello,

I have a webpage with 2 Radgrids on it. One is the master and the other the detail views.
When I click on a record on the master grid it displays all related records on the detail grid.
My question is:
When I add a new record to the detail view grid, the ID is not prepopulated for that record. Is there a way I can populate that ID field with the id from the selected record in the master grid?
For example if the master grid has customers and the details grid has orders. When I select customer 11 it shows all orders for that customer. But when I add a new order on the second grid, I would like to autopopulate the customer ID with the number 11.

Thanks in advance for any help with this.

2 Answers, 1 is accepted

Sort by
0
Tom Edward
Top achievements
Rank 1
answered on 23 Aug 2010, 09:43 PM
anyone please?
0
Princy
Top achievements
Rank 2
answered on 25 Aug 2010, 06:47 AM
Hello Tom,

Try the following code snippet in ItemDataBound event to achieve this.

ASPX:
<telerik:RadGrid ID="RadGrid1">
    <MasterTableView Name="Master" runat="server" DataKeyNames="CustomerID">
       <DetailTables>
            <telerik:GridTableView Name="GridTableView1" >
            </telerik:GridTableView>
        </DetailTables>
    </MasterTableView>
</telerik:RadGrid>

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
   {
      if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted && e.Item.OwnerTableView.Name == "GridTableView1")
       {
           GridEditFormInsertItem insertItem = (GridEditFormInsertItem)e.Item;
           GridDataItem parentitem = (GridDataItem)insertItem.OwnerTableView.ParentItem;
           TextBox txt = (TextBox)insertItem["CustomerID"].Controls[0];
           txt.Text = parentitem.GetDataKeyValue("CustomerID").ToString();
       }
   }

Thanks,
Princy.
Tags
Grid
Asked by
Tom Edward
Top achievements
Rank 1
Answers by
Tom Edward
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or