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

DetailTable insert from parent table?

2 Answers 88 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sypher
Top achievements
Rank 1
Sypher asked on 01 Jun 2011, 07:50 PM
I would like to have a GridButtonColumn that begins an Insert in the DetailsTable under the current row.  Is this possible?  Basically, I can do an insert in the DetailsTable by showing the command row, but that row doesn't fit well in my grid and I would like to have the Add button show up in the parent row instead.  I have a button and can catch the ItemCommand from the main grid, but can I initiate the Insert in the details table from there?

protected void g1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == "AddPI")
    {
        // What goes here to init insert in detailstable[0]?
        //e.Item.OwnerTableView.DetailTables[0].???
    }
 
}

2 Answers, 1 is accepted

Sort by
0
Accepted
Vasil
Telerik team
answered on 07 Jun 2011, 08:30 AM
Hello,

I believe that the following code will work for you.

if (e.CommandName == "AddPI")
{
    ((e.Item as GridDataItem).ChildItem as GridNestedViewItem).NestedTableViews[0].InsertItem();
}

Here is a full example.
Aspx:
<telerik:RadGrid ID="grdViewRegistries" runat="server" OnNeedDataSource="grdViewRegistries_NeedDataSource">
  <MasterTableView>
    <Columns>
      <telerik:GridButtonColumn CommandName="AddPI" Text="add">
      </telerik:GridButtonColumn>
    </Columns>
    <DetailTables>
      <telerik:GridTableView>
      </telerik:GridTableView>
    </DetailTables>
  </MasterTableView>
</telerik:RadGrid>

C#:
protected void Page_Load(object sender, EventArgs e)
{
    grdViewRegistries.ItemCommand += new GridCommandEventHandler(grdViewRegistries_ItemCommand);
}
 
void grdViewRegistries_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == "AddPI")
    {
        ((e.Item as GridDataItem).ChildItem as GridNestedViewItem).NestedTableViews[0].InsertItem();
    }
}
protected void grdViewRegistries_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    (sender as RadGrid).DataSource = new int[] { 1, 2, 3, 4 };
}

See this help topic for additional information:
http://www.telerik.com/help/aspnet-ajax/grid-traversing-detail-tables-items-in-grid.html

All the best,
Vasil
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Sypher
Top achievements
Rank 1
answered on 07 Jun 2011, 02:15 PM
Cool. :-) Just FYI, JustCode told me that the second cast wasn't needed, so this works:

((e.Item as GridDataItem).ChildItem).NestedTableViews[0].InsertItem();
Tags
Grid
Asked by
Sypher
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Sypher
Top achievements
Rank 1
Share this question
or