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

[Solved] How to bind the detailsTable in the code behind

2 Answers 142 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Qaja Mohiddin
Top achievements
Rank 1
Qaja Mohiddin asked on 18 May 2009, 03:55 AM
Hi All,

 I want to bind the gird using code behind. Iam able to bind the grid in code behind, but how to bind the detailstable in the code bind .here is my code. can any one please let me know, how can i do this ........


Pls its very urgent as i have to bind the record depeding upon the values selected. so iam doing this way.



 protected void RadGrid1_PreRender(object sender, EventArgs e)  
        {  
            foreach (GridDataItem item in RadGrid1.MasterTableView.Items)  
            {  
                if (item.Expanded)  
                {  
                    RadGrid1.MasterTableView.DetailTables[0].DataSource = GetData(new SqlCommand("select regionID,RegionDescription from region"));  
                    RadGrid1.MasterTableView.DetailTables[0].DataBind();  
                    RadGrid1.MasterTableView.DetailTables[0].Visible=true;  
                      
                        }  
        } 




<telerik:RadGrid ID="RadGrid1" OnPreRender="RadGrid1_PreRender" runat="server" Skin="Web20" 
    AutoGenerateColumns="False" AllowSorting="True" 
            AllowPaging="True" PageSize="5" GridLines="None" ShowGroupPanel="True" OnItemDataBound="RadGrid1_ItemDataBound"   
            > 
                          
 
             <MasterTableView NoMasterRecordsText="" DataKeyNames="RegionID" 
                            Width="100%" ClientDataKeyNames="RegionID" TableLayout="Fixed">  
                            <Columns> 
                                <telerik:GridBoundColumn HeaderText="RegionID" DataField="RegionID" UniqueName="RegionID">  
                                    <HeaderStyle Width="75px" /> 
                                </telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn HeaderText="Region" DataField="Region"   
                                UniqueName="Region">  
                                  </telerik:GridBoundColumn> 
                                    <telerik:GridBoundColumn HeaderText="Total Sales" DataField="Total Sales"   
                                UniqueName="Total Sales">  
                                </telerik:GridBoundColumn> 
                                  <telerik:GridBoundColumn HeaderText="Total Quantity" DataField="Total Quantity"   
                                UniqueName="Total Quantity">  
                                </telerik:GridBoundColumn> 
                                 <telerik:GridBoundColumn HeaderText="Company Name" DataField="Company Name"   
                                UniqueName="Company Name">  
                                </telerik:GridBoundColumn> 
                                 <telerik:GridBoundColumn HeaderText="Percent Sales" DataField="Percent Sales"   
                                UniqueName="Percent Sales">  
                                 <HeaderStyle Width="138px" /> 
                                </telerik:GridBoundColumn> 
                                                               
                            </Columns> 
                           
                          <DetailTables> 
                            
                          <telerik:GridTableView AutoGenerateColumns="false" GridLines="none" DataKeyNames="RegionID" ClientDataKeyNames="RegionID" Width="100%" Height="100%">  
                           <ParentTableRelation> 
                                <telerik:GridRelationFields DetailKeyField="RegionID" MasterKeyField="RegionID" /> 
                            </ParentTableRelation> 
                          <Columns> 
                            
                          <telerik:GridBoundColumn Headertext="Region" DataField="RegionID" UniqueName="RegionID"></telerik:GridBoundColumn> 
                          <telerik:GridBoundColumn HeaderText="RegionDescription" DataField="RegionDescription" UniqueName="RegionDescription"></telerik:GridBoundColumn> 
                                                     
                          </Columns> 
                          </telerik:GridTableView> 
                          </DetailTables> 
                                                
               </MasterTableView> 
              
          
    </telerik:RadGrid> 

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 18 May 2009, 04:10 AM
Hi Qaja,

Try binding the Detail table in the DetailTableDataBind event as shown in the following online demo.
Programmatic Binding

Princy.
0
Qaja Mohiddin
Top achievements
Rank 1
answered on 18 May 2009, 04:51 AM
hi

Thnxk for the reply. this really helped me .

Can you pls let me know,
iam using treeview to bind the grid on the selected node. Iam able to bind the grid on the selected node.
but the problem is, when i click on +, the tree is expanding. i want the grid to be binded when it clciked on + symbol. But  iam able to bind only when the value is selected.

can you help me out for this..
pls its very urgent...............


Tags
Grid
Asked by
Qaja Mohiddin
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Qaja Mohiddin
Top achievements
Rank 1
Share this question
or