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

[Solved] Bind template fields like (text box / dropdown) in Hierarchical / Details table in Grid

1 Answer 89 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Phani
Top achievements
Rank 1
Phani asked on 28 Jan 2010, 07:43 PM

I didnot get the proper search results when i try to find (Bind template fields like (text box / dropdown) in Hierarchical / Details table in Grid). So, i posted here for just documentation purposes.
 

 <telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True" 
                        AllowSorting="True" GridLines="None" AutoGenerateColumns="False" Skin="WebBlue" 
                        EnableEmbeddedSkins="False" AllowMultiRowSelection="True">  
                        <MasterTableView TableLayout="Fixed" CellSpacing="-1" HierarchyLoadMode="Client" 
                            DataKeyNames="parent_Id">  
                            <DetailTables> 
                                <telerik:GridTableView Name="DetailsTable1" Width="100%" AllowFilteringByColumn="False" 
                                    runat="server">  
                                    <Columns> 
                                        <telerik:GridClientSelectColumn HeaderText="" UniqueName="CheckboxSelectColumn" HeaderStyle-Width="35px" 
                                            ItemStyle-Width="35px" /> 
 
                                        <telerik:GridBoundColumn FilterControlWidth="75px" DataField="child_Id" HeaderText="CHILD ID" 
                                            SortExpression="child_Id" UniqueName="child_Id" /> 
 
                                        <telerik:GridTemplateColumn HeaderText="RANK" AllowFiltering="False" SortExpression="Rank" 
                                            UniqueName="Rank">  
                                            <ItemTemplate> 
                                                <telerik:RadNumericTextBox ID="radRankInsideGrid" runat="server" NumberFormat-DecimalDigits="0" 
                                                    NumberFormat-GroupSeparator="" Type="Number" MaxLength="6" Width="40px" DataType="Integer">  
                                                </telerik:RadNumericTextBox> 
                                            </ItemTemplate> 
                                            <HeaderStyle HorizontalAlign="Center" /> 
                                            <ItemStyle HorizontalAlign="Center" /> 
                                        </telerik:GridTemplateColumn> 
 
                                        <telerik:GridTemplateColumn HeaderText="SELECTED" AllowFiltering="False" SortExpression="SelectedDesc" 
                                            UniqueName="Selected">  
                                            <ItemTemplate> 
                                                <telerik:RadComboBox ID="radSelectedInsideGrid" DataTextField="SelectedDesc" DataValueField="SelectedID" 
                                                    Width="100px" runat="server" EnableLoadOnDemand="true" AllowCustomText="false" 
                                                    OnItemsRequested="radSelectedInsideGrid_ItemsRequested" /> 
                                            </ItemTemplate> 
                                            <HeaderStyle HorizontalAlign="Center" /> 
                                            <ItemStyle HorizontalAlign="Center" /> 
                                        </telerik:GridTemplateColumn> 
                                         
                                    </Columns> 
                                </telerik:GridTableView> 
                            </DetailTables> 
                            <Columns> 
                                <telerik:GridBoundColumn  Visible="False" DataField="parent_Id" UniqueName="parent_Id" /> 
                                <telerik:GridBoundColumn DataField="Name" HeaderText="NAME" SortExpression="Name" 
                                    UniqueName="Name" FilterControlWidth="75%" /> 
                                <telerik:GridBoundColumn DataField="Type" HeaderText="TYPE" SortExpression="Type" 
                                    UniqueName="Type" FilterControlWidth="75%" /> 
                                <telerik:GridDateTimeColumn DataFormatString="{0:d}" DataField="StartDate" 
                                    FilterListOptions="VaryByDataType" HeaderText="START DATE" SortExpression="StartDate" 
                                    UniqueName="StartDate" HeaderStyle-Width="140px" FilterControlWidth="100px" /> 
                           </Columns> 
                        </MasterTableView>         
 </telerik:RadGrid> 

code behind:

Private Sub RadGrid1_NeedDataSource(ByVal source As ObjectByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource  
   If Not e.IsFromDetailTable Then 
      RadGrid1.DataSource = ParentBindData()  
   End If 
End Sub

 

 Private Sub RadGrid1_DetailTableDataBind(ByVal source As ObjectByVal e As Telerik.Web.UI.GridDetailTableDataBindEventArgs) Handles RadGrid1.DetailTableDataBind  
        Dim dataItem As GridDataItem = CType(e.DetailTableView.ParentItem, GridDataItem)  
        Select Case e.DetailTableView.Name.ToUpper()  
            Case "DETAILSTABLE1" 
                Dim obj As New ClassName  
                obj.Id = dataItem.GetDataKeyValue("parent_Id").ToString()  
                  
                e.DetailTableView.DataSource = obj.bindResults()  
 
                objPI = Nothing 
        End Select 
 End Sub 

 

 Private Sub RadGrid1_ItemDataBound(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound  
        If e.Item.OwnerTableView.Name = "DetailsTable1" And _  
        (e.Item.ItemType = GridItemType.Item Or e.Item.ItemType = GridItemType.AlternatingItem) Then 
 
            'Grid Item  
            Dim objGridItem As GridDataItem  
            objGridItem = CType(e.Item, GridDataItem)  
 
            'Rank  
            Dim objRadTextBox As RadNumericTextBox  
            objRadTextBox = CType(objGridItem("Rank").FindControl("radRankInsideGrid"), RadNumericTextBox)  
            If Not IsNothing(objRadTextBox) Then 
                objRadTextBox.Text = e.Item.DataItem("Rank").ToString()  
            End If 
 
            'Selected, re-using the same objRadComboBox object.  
            Dim objRadComboBox1 As RadComboBox  
            objRadComboBox1 = CType(objGridItem("Selected").FindControl("radSelectedInsideGrid"), RadComboBox)  
            If Not IsNothing(objRadComboBox1) And e.Item.DataItem("SelectedID").ToString() <> String.Empty Then 
                GetSelectedLKUP(objRadComboBox1)  
                objRadComboBox1.SelectedValue = e.Item.DataItem("SelectedID").ToString()  
            End If 
 
        End If 
    End Sub 

 

 Private Sub GetSelectedLKUP(ByVal objRadComboBox As RadComboBox, Optional ByVal customText As String = "")     
        Dim objLookup As New Lookup     
        Dim objDataSet As DataSet = objLookup.bindSelectedLKUP()     
    
        objRadComboBox.DataSource = objDataSet     
        objRadComboBox.DataBind()     
    
        objLookup = Nothing    
 End Sub    
 
    Protected Sub radSelectedInsideGrid_ItemsRequested(ByVal sender As ObjectByVal e As Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs)     
        Dim objRadComboBox As RadComboBox = DirectCast(sender, RadComboBox)     
        objRadComboBox.Items.Clear()     
        GetSelectedLKUP(objRadComboBox, e.Text)     
    End Sub   

1 Answer, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 02 Feb 2010, 03:24 PM
Hi Phani,

Thank you for sharing your experience and findings with the Telerik community. I am sure that this forum post will prove helpful for those who need this functionality.

Kind regards,
Radoslav
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
Tags
Grid
Asked by
Phani
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Share this question
or