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

[Solved] Radgrid Detailtable Issues

2 Answers 367 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Monique Smartt
Top achievements
Rank 1
Monique Smartt asked on 18 Jun 2009, 09:12 PM
I am working with a detailtable in radgrid and need to do a couple things that I have done on the radgrid, but it is not working in the detail table.

1) I am using client onrowclick to open window, which works fine in master table, but not in detail table. I need to somehow get the innerHTML of the cell of the clicked detailtable row.
function RowClick(sender, eventArgs)  
    var MasterTableView = eventArgs.get_tableView(); 
    var cell = MasterTableView.getCellByColumnUniqueName(MasterTableView.get_dataItems()[eventArgs.get_itemIndexHierarchical()], "ID"); 
    window.open("../ClientInformation.aspx?ClienteID=" + cell.innerHTML);  
 
 

2) I have some checkboxes that are used to control the columns displayed. It happens on server side, after binding the grid. The function works, but the detail table only removes the column on second databind. So basically I run report showing all columns, works fine. Then I uncheck a check box and run report, master column is removed, but detail column remains. Finally leaving checkboxes alone I run report again and both master and detail column is removed, which is what I want. Why is it not happening on first bind?
 
 
        private void CustomizeGrid() 
        { 
            foreach (ListItem li in chkDisplayColumns.Items) 
            { 
                if (!li.Selected) 
                { 
                    gridResults.Columns.FindByUniqueName(li.Value).Visible = false
                    gridResults.MasterTableView.DetailTables[0].Columns.FindByDataField(li.Value).Visible = false
                } 
                else 
                { 
                    gridResults.Columns.FindByUniqueName(li.Value).Visible = true
                    gridResults.MasterTableView.DetailTables[0].Columns.FindByDataField(li.Value).Visible = true
                } 
            } 
        } 

Any help is appreciated.


2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 19 Jun 2009, 10:56 AM
Hello Monique,

You can check out the follwoing code snippets to solve your issues:
aspx:
<asp:checkboxlist id="CheckBoxList1" autopostback="true" runat="server" onselectedindexchanged="CheckBoxList1_SelectedIndexChanged">  
                <asp:ListItem Text="Column1"></asp:ListItem>  
                <asp:ListItem Text="Column2"></asp:ListItem>  
            </asp:checkboxlist> 
<telerik:RadGrid ID="RadGrid2" runat="server" AutoGenerateColumns="false" DataSourceID="Sqldatasource1">
    
    <MasterTableView Name="Master"
        <Columns> 
            ... 
            <telerik:GridBoundColumn HeaderText="Column1" DataField="Column1" UniqueName="Column1" 
                Visible="false"
            </telerik:GridBoundColumn> 
            <telerik:GridBoundColumn HeaderText="Column2" DataField="Column2" UniqueName="Column2" 
                Visible="false"
            </telerik:GridBoundColumn> 
        </Columns> 
        <DetailTables> 
            <telerik:GridTableView AutoGenerateColumns="false" DataSourceID="Sqldatasource1" 
                Name="Detail"
                <Columns> 
                    .... 
                    <telerik:GridBoundColumn HeaderText="Column1" DataField="Column1" UniqueName="Column1" 
                        Visible="false"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn HeaderText="Column2" DataField="Column2" UniqueName="Column2" 
                        Visible="false"
                    </telerik:GridBoundColumn> 
                </Columns> 
            </telerik:GridTableView> 
        </DetailTables> 
    </MasterTableView> 
    <ClientSettings> 
        <ClientEvents OnRowClick="RowClick" /> 
    </ClientSettings> 
</telerik:RadGrid> 

1) To get the innerHTML of the cell in the clicked detailtable row:
js:
function RowClick(sender, eventArgs)   
     {            
        var MasterTableView = eventArgs.get_tableView(); 
        var index =  eventArgs.get_itemIndexHierarchical();    
          if(MasterTableView.get_name()=="Master")    
            { 
                var cell = MasterTableView.getCellByColumnUniqueName(MasterTableView.get_dataItems()[index], "FirstName");  
                alert(cell.innerHTML); 
            }         
          if(MasterTableView.get_name()=="Detail")  
            {     
                var valueindex = index.lastIndexOf("_") ;   
                var value = index.substr(valueindex+1,index.length); 
                var cell = MasterTableView.getCellByColumnUniqueName(MasterTableView.get_dataItems()[value], "FirstName");  
                alert(cell.innerHTML); 
            } 
     }  

2) Try rebinding the grid after hiding the columns:
c#:
 protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e) 
    { 
        foreach (ListItem li in CheckBoxList1.Items) 
        { 
            if (!li.Selected) 
            { 
                RadGrid1.Columns.FindByUniqueName(li.Text).Visible = false
                RadGrid1.MasterTableView.DetailTables[0].Columns.FindByDataField(li.Text).Visible = false;            
            } 
            else 
            { 
                RadGrid1.Columns.FindByUniqueName(li.Text).Visible = true
                RadGrid1.MasterTableView.DetailTables[0].Columns.FindByDataField(li.Text).Visible = true
            } 
            RadGrid1.Rebind(); 
        }  
    } 

Thanks
Princy.
0
Monique Smartt
Top achievements
Rank 1
answered on 19 Jun 2009, 04:04 PM
Thank you! These worked perfectly.
Tags
Grid
Asked by
Monique Smartt
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Monique Smartt
Top achievements
Rank 1
Share this question
or