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

accessing rows in detailtable

7 Answers 340 Views
Grid
This is a migrated thread and some comments may be shown as answers.
MBEN
Top achievements
Rank 2
Veteran
MBEN asked on 30 Nov 2011, 12:01 AM
Hi,

I have a scenario where I need to loop through the number of rows in the detail table for each row and read the columns in the detail table.

I am binding my grid to a datasource with the relation defined.
I am unable to read the child rows in my ItemDataBound event. I tried using dataItem.childItem but my child Item always comes null.

I am not sure my detail table is getting any data or not.
I don't want to show my detail table to the user just want to read the values in the detail table.

Below is how my detail table is defined:
<MasterTableView TableLayout="Fixed" HierarchyDefaultExpanded="true" CommandItemDisplay="Top"
                        EnableNoRecordsTemplate="true">                                             
                        <Columns>
                            ......
                        </Columns>
                        <DetailTables>
                            <telerik:GridTableView DataKeyNames="AccountID" Width="100%" DataMember="FundBalance" HierarchyLoadMode="ServerBind">
                                <ParentTableRelation>
                                    <telerik:GridRelationFields DetailKeyField="AccountID" MasterKeyField="AccountID" />
                                </ParentTableRelation>
                                <Columns>
                                    <telerik:GridBoundColumn DataField="AccountID" UniqueName="AccountID">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="FundTypeID" UniqueName="FundTypeID">
                                    </telerik:GridBoundColumn>                                   
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn UniqueName="BeginBalanceShares" DataField="BeginBalanceShares">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn UniqueName="BeginPrice" DataField="BeginPrice" >
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn UniqueName="BeginBalanceDollars" DataField="BeginBalanceDollars">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn UniqueName="EndBalanceShares" DataField="EndBalanceShares">
                                    </telerik:GridBoundColumn>
                                </Columns>
                            </telerik:GridTableView>
                        </DetailTables>
                    </MasterTableView>
 
 
My datasource is defined as:
 
public static DataTable ListByPlanAndDateRange(int planID, DateTime beginDate, DateTime endDate)
        {
            DataSet ds = DBRoutines.wusp_PeriodSummaryByFund_ListByPlanAndDateRange(planID, beginDate, endDate);
            ds.Tables[0].TableName = "FundBalance";
            ds.Tables[1].TableName = "SourceContribution";
            ds.Relations.Add("BalanceRelation", ds.Tables[0].Columns[Fields.FundID], ds.Tables[1].Columns[Fields.FundID], false);
            return ds.Tables[0];
        }

Basically I have a asp.net gridview to migrate from and currently I am using this to access the child rows:
protected void balances_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataRowView drv = (DataRowView)e.Row.DataItem;
                DataRow[] drSubBalance = drv.Row.GetChildRows("BalanceRelation");
            }
        }
I want to do something similar in radgrid.

I have spent 2 days trying to figure this out. Please provide some help!

7 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 30 Nov 2011, 05:43 AM
Hello,

Try the following code.
C#:
protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e)
{
 if (e.Item is  GridDataItem &&  e.Item.OwnerTableView.Name == "DetailTable1")
 {
   GridDataItem dataitem = (GridDataItem)e.Item;
   TextBox txt = (TextBox)dataitem["BalanceRelation"].Controls[0];
 }
}

-Shinu.
0
MBEN
Top achievements
Rank 2
Veteran
answered on 02 Dec 2011, 06:05 AM
I had to bind my master and detail table to seperate data sources respectively and that seems to work.

However, I am having a different issue now.
I do not want to display my detail table. That table is used for some calculations and I show those result on hover over a particular column.
I set the Visible="true" in the detailview but that leaves an empty line in the grid display. I want to remove that extra line.
Attached is a screenshot.
0
Shinu
Top achievements
Rank 2
answered on 02 Dec 2011, 06:25 AM
Hello,

Try setting the GridLines as None.
aspx:
<telerik:GridTableView Visible="false" GridLines="None" Name="DetailTable1">
</telerik:GridTableView>

-Shinu.
0
MBEN
Top achievements
Rank 2
Veteran
answered on 02 Dec 2011, 06:15 PM
Unfortunately, that did not work.
Any other ideas.
0
MBEN
Top achievements
Rank 2
Veteran
answered on 06 Dec 2011, 10:18 PM
I have attached a screenshot of the grid with extra spacing where i hide the detail table.
Please help me resolve this, this is taking up a lot of space on the page.
0
Andrey
Telerik team
answered on 07 Dec 2011, 04:55 PM
Hi Mben,

You could achieve your goal by hooking the PreRender event of RadGrid and in its body to get the NestedViewItems of the desired GridTableView. Then on each of these items set the Visible property to false.

In C# code this should be something similar to this:

protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    HideNestedViewItems(RadGrid1.MasterTableView);
}
 
public void HideNestedViewItems(GridTableView tableView)
{
    GridItem[] nestedViewItems = tableView.GetItems(GridItemType.NestedView);
    foreach (GridNestedViewItem nestedViewItem in nestedViewItems)
    {
        nestedViewItem.Visible = false;
    }
}

And in VB.NET

Protected Sub RadGrid1_PreRender(sender As Object, e As EventArgs)Handles RadGrid1.PreRender
    HideNestedViewItems(RadGrid1.MasterTableView)
End Sub
 
Public Sub HideNestedViewItems(tableView As GridTableView)
    Dim nestedViewItems As GridItem() = tableView.GetItems(GridItemType.NestedView)
    For Each nestedViewItem As GridNestedViewItem In nestedViewItems
        nestedViewItem.Visible = False
    Next
End Sub

Give these suggestion a try and check whether the issue is resolved.

Best wishes,
Andrey
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
MBEN
Top achievements
Rank 2
Veteran
answered on 07 Dec 2011, 09:48 PM
Thanks, that worked.
Tags
Grid
Asked by
MBEN
Top achievements
Rank 2
Veteran
Answers by
Shinu
Top achievements
Rank 2
MBEN
Top achievements
Rank 2
Veteran
Andrey
Telerik team
Share this question
or