DetailTable insert from parent table?

3 posts, 1 answers
  1. Sypher
    Sypher avatar
    79 posts
    Member since:
    Aug 2006

    Posted 01 Jun 2011 Link to this post

    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. Answer
    Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 07 Jun 2011 Link to this post

    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.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Sypher
    Sypher avatar
    79 posts
    Member since:
    Aug 2006

    Posted 07 Jun 2011 Link to this post

    Cool. :-) Just FYI, JustCode told me that the second cast wasn't needed, so this works:

    ((e.Item as GridDataItem).ChildItem).NestedTableViews[0].InsertItem();
Back to Top