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

Radgrid Detailtable expand and in editmode

7 Answers 247 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 1
Eric asked on 17 Sep 2008, 07:54 AM
I have a radgrid (multi select) which is set in editmode through a button eventhandler. Now I had to add a detailtable which is displayed correct.
However, what I want is when a row in the mastertable is selected, and the edit putton is clicked, the detailtable has to expand and has to be put in edit mode. I can't get this done. This is what I have:

protected void button_Click(object sender, EventArgs e) {

bool isInEditMode = false;

foreach (GridItem item in rg.MasterTableView.Items) {                           

    if (item.Selected){

        if (item is GridEditableItem){

            ((GridEditableItem) item).Edit = true;

            isInEditMode = true;

        }

        if (item is GridDataItem){

            GridTableView nestedView = ((GridDataItem)item).ChildItem.NestedTableViews[0];

            if (tmp.Name == "Pricing"){

                item.Expanded = true;

                item.Edit = true;

            }

        }

       

        item.Selected = false;

    }

}

if (isInEditMode) {

    // disable selecting because we're in edit mode

    rg.ClientSettings.Selecting.AllowRowSelect = false;

    rg.Rebind();

}

}

if (isInEditMode) {

    // disable selecting because we're in edit mode

    rg.ClientSettings.Selecting.AllowRowSelect = false;

    rg.Rebind();

<Philips:MagAgRadGrid ID="rg" runat="server" AllowSorting="True" OnNeedDataSource="rg_NeedDataSource" AllowMultiRowEdit="True" OnItemCommand="rg_ItemCommand" Skin="Outlook" AllowMultiRowSelection="True" EnableOutsideScripts="True" EnableViewState="true" OnDetailTableDataBind="rg_DetailTableDataBind" >

..........

..........

<DetailTables>

    <radG:GridTableView DataKeyNames="MarketProductID" Name="Pricing"  Width="100%" AutoGenerateColumns="false" >

        <ParentTableRelation>

            <radG:GridRelationFields DetailKeyField="MarketProductID" MasterKeyField="MarketProductID" />

        </ParentTableRelation>

        <Columns>

            <radG:GridBoundColumn SortExpression="Country" HeaderText="Country"  DataField="Name"></radG:GridBoundColumn>

            <radG:GridTemplateColumn HeaderText="AVNP" UniqueName="AVNP" SortExpression="AVNP">

                <ItemStyle VerticalAlign="Top" HorizontalAlign="Center" />

                <ItemTemplate>

                    <asp:Label ID="lblAVNP" runat="server" Text='<%# Eval("AVNP") == DBNull.Value ? " 0.00" : Convert.ToDouble(Eval("AVNP")).ToString(" #0.00") %>' ></asp:Label>                            

                </ItemTemplate>

                <EditItemTemplate>

                    <radG:RadNumericTextBox ID="txtAVNP" runat="server" MinValue="0" EnabledStyle-HorizontalAlign="Right" Skin="Outlook" Value='<%# Eval("AVNP") %>' Width="60px">

                   <NumberFormat DecimalDigits="2" GroupSeparator="" />

                    </radG:RadNumericTextBox>

                </EditItemTemplate>

            </radG:GridTemplateColumn>

        </Columns>

    </radG:GridTableView>           

</DetailTables>

..........

..........

I hope anybody can help me.


7 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 1
answered on 17 Sep 2008, 12:53 PM
Hi Eric,

Try the following code snippet to achieve the desired scenario.

CS:
protected void Button1_Click(object sender, EventArgs e) 
    { 
        foreach (GridDataItem item in RadGrid1.SelectedItems) 
        { 
            item.Edit = true
            item.Expanded = true
            if (item.Expanded) 
            { 
                GridTableView nestedView = ((GridDataItem)item).ChildItem.NestedTableViews[0]; 
                foreach (GridDataItem childitem in nestedView.GetItems(GridItemType.Item)) 
                { 
                    childitem.Edit = true
                } 
            } 
        } 
        RadGrid1.Rebind(); 
       
        
    } 


Regards
Princy.
0
Eric
Top achievements
Rank 1
answered on 17 Sep 2008, 01:53 PM
Princy, thank you very much. This works.
0
Ian
Top achievements
Rank 1
answered on 28 Jun 2012, 06:01 PM
How can I achieve the same thing but instead of edit mode; how can I have the child grid open in insert mode? I tried a number of different things but it keeps saying that it can't find my linq datasource control when I rebind at the detail level or the master level. I need to be able to expand a row with command button and have the child detail grid loaded in insert mode all in one click.

When the rebind is called here at any level it yields this from ajax postback.
69|error|500|Cannot find DataSourceControl with ID 'ldsVendorRatingQualifications'|


Thanks!

protected void gridRatings_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
    if (e.CommandName == "AddNewChildRating") {
                GridDataItem parentRow = e.Item as GridDataItem;
                GridTableView parentGridView = parentRow.GetClosestParentControlByType<GridTableView>();
                RadGrid parentGrid = parentGridView.GetClosestParentControlByType<RadGrid>();
  
                parentRow.Expanded = true;
                //parentGridView.HierarchyDefaultExpanded = true;
                //parentGridView.DetailTables[0].InsertItem();
                parentGridView.DetailTables[0].IsItemInserted = true;
                parentGridView.DetailTables[0].Rebind();
    }
}
0
Eyup
Telerik team
answered on 03 Jul 2012, 11:24 AM
Hello Lan,

I have attached a sample RadGrid web site where I demonstrated how to expand and init insert on single click. Please check out the attached application and try to implement it on your own project.

If the binding problem still remains please closely examine your datasource declaration and grid databinding. In case the issue persists, please open a support ticket and send us a runnable application demonstrating the erratic behavior. Thus, we will be able to further analyze the issue and provide a proper solution.

Regards,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Greg
Top achievements
Rank 1
answered on 16 Jul 2014, 08:44 PM
In the project Eyup attached RadGridExpandAndInitInsert.zip, the solution works as long as there is a nested view... if there are no detail items, nestedview is nothing and throws and error.

So how would you initiate the InitInsert in the case where there is no nestedView for the parent row that originates the button click?

...exerpt from RadGrid1_ItemCommand

Dim parentRow As GridDataItem = CType(e.Item, GridDataItem)
parentRow.Expanded = True
Dim nestedView As GridTableView = parentRow.ChildItem.NestedTableViews(0)
nestedView.Items(0).FireCommandEvent("InitInsert", String.Empty)
0
Greg
Top achievements
Rank 1
answered on 16 Jul 2014, 08:50 PM
In response to my last post...

nestedView doesn't result in nothing... nestedView.Items(0) throws "index out of range"...
0
Greg
Top achievements
Rank 1
answered on 16 Jul 2014, 09:04 PM
... never mind, found it : http://www.telerik.com/forums/open-detailtable-edit-form#rjT4EC2BWkCLduEeoY8b6A

Tags
Grid
Asked by
Eric
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Eric
Top achievements
Rank 1
Ian
Top achievements
Rank 1
Eyup
Telerik team
Greg
Top achievements
Rank 1
Share this question
or