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

item bound error in hierarchy

1 Answer 21 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Webster Velasco
Top achievements
Rank 2
Webster Velasco asked on 12 Mar 2010, 04:33 PM
hi

im having a poblem when i try to expand my childtable on my data grid..

to be clear i have a prob on itemdatabound event


        If TypeOf e.Item Is GridDataItem Then 
            Dim dataItem As GridDataItem = DirectCast(e.Item, GridDataItem) 
            Dim DateDiff As Int32 = Convert.ToInt32(dataItem("colDTDIFF").Text) 
            If DateDiff <= 30 Then 
                dataItem.BackColor = Drawing.Color.IndianRed 
            ElseIf DateDiff <= 60 Then 
                dataItem.BackColor = Drawing.Color.Yellow 
            ElseIf DateDiff <= 90 Then 
                dataItem.BackColor = Drawing.Color.SpringGreen 
            End If 
        End If 
    End Sub

Dim DateDiff As Int32 = Convert.ToInt32(dataItem("colDTDIFF").Text) --> erro from this line


here my aspx code:
                   <telerik:RadGrid ID="grdCrediti" DataSourceID="objDSScont" runat="server" Width="99.7%" 
                        AutoGenerateColumns="False" PageSize="15" AllowSorting="True" AllowPaging="True" ShowHeader="true" 
                        GridLines="None" ShowStatusBar="true" AllowAutomaticUpdates="true"
                        <PagerStyle Mode="NumericPages"></PagerStyle> 
                        <MasterTableView DataSourceID="objDSScont" AllowMultiColumnSorting="True" 
                            Width="100%" DataKeyNames="CODICE"
                            <Columns> 
                                <telerik:GridBoundColumn SortExpression="DESCRIZIONE" HeaderText="Servizio" DataField="DESCRIZIONE" UniqueName="colDESCRIZIONE"
                                </telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn SortExpression="DTORDINE" HeaderText="Data Ordine" DataField="DTORDINE" UniqueName="colDTORDINE"
                                </telerik:GridBoundColumn>    
                                <telerik:GridBoundColumn SortExpression="DTSCADENZA" HeaderText="Data Scadenza" DataField="DTSCADENZA" UniqueName="colDTSCADENZA"
                                </telerik:GridBoundColumn>  
                                <telerik:GridBoundColumn HeaderText="Giorni Residui" DataField="DTDIFF" UniqueName="colDTDIFF" AllowSorting="false"
                                </telerik:GridBoundColumn>                                                                                       
                            </Columns> 
                            <DetailTables> 
                                <telerik:GridTableView AutoGenerateColumns="false" Caption="Dettaglio Servizi" AllowSorting="false" 
                                    DataSourceID="objDETT" Width="100%" PageSize="7"
                                    <ParentTableRelation> 
                                        <telerik:GridRelationFields DetailKeyField="CODICE" MasterKeyField="CODICE" /> 
                                    </ParentTableRelation> 
                                    <PagerStyle AlwaysVisible="false" /> 
                                    <Columns> 
                                        <telerik:GridBoundColumn SortExpression="DESCRIZIONE" HeaderText="Descrizione" DataField="DESCRIZIONE" UniqueName="colDESCRIZIONE"
                                        </telerik:GridBoundColumn> 
                                        <telerik:GridBoundColumn SortExpression="QUANTITA" HeaderText="Ordinato" DataField="QUANTITA" UniqueName="colQUANTITA"
                                        </telerik:GridBoundColumn>    
                                        <telerik:GridBoundColumn SortExpression="QUANTITAINS" HeaderText="Utilizzato" DataField="QUANTITAINS" UniqueName="colQUANTITAINS"
                                        </telerik:GridBoundColumn>    
                                        <telerik:GridBoundColumn SortExpression="RESIDUO" HeaderText="Residuo" DataField="RESIDUO" UniqueName="colQUANTITAINS" AllowSorting="false"
                                        </telerik:GridBoundColumn>  
                                        <telerik:GridBoundColumn HeaderText="Giorni Residui" DataField="DTDIFF" UniqueName="colDTDIFF" visible="false"
                                        </telerik:GridBoundColumn>                                                                                                                            
                                    </Columns> 
                                </telerik:GridTableView> 
                            </DetailTables>                             
                        </MasterTableView> 
                    </telerik:RadGrid> 

need answer asap

thanks

regards
webster



1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 1
answered on 15 Mar 2010, 08:11 AM
Hi,

You can set the Name property for your detailtable of your grid. Then in the ItemDataBound event of the grid, you can check for the Name of the ownertableview and access the item accordingly:

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" OnItemDataBound="RadGrid1_ItemDataBound">   
       <MasterTableView Name="Master" DataSourceID="SqlDataSource1">  
              <DetailTables>  
                    <telerik:GridTableView DataSourceID="SqlDataSource2" Name="Detail" runat="server">                   

c#:
 protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "Detail"// to check for the detail table 
        { 
            GridDataItem childItem = (GridDataItem)e.Item; 
        } 
    } 

Hope this helps..
Princy.
Tags
Grid
Asked by
Webster Velasco
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 1
Share this question
or