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

Collapse after timer ticks

1 Answer 47 Views
Grid
This is a migrated thread and some comments may be shown as answers.
fredn
Top achievements
Rank 1
fredn asked on 08 Oct 2008, 12:58 PM
Hello,

I have a grid with for each item a detail table. The data for this grid are filled out using NeedDataSource and DetailTableDataBind events.
I also have a time which is in charge of rebinding the grid every 5 seconds.

My problem comes when I have expanded an item of the grid, in order to see its detail table, and the timer ticks. Then the item is automatically collapsed...

How can I avoid this automatic collapsing.
My Telerik version is v2008.1.619.35.

Here are sample codes :

 
<telerik:RadStyleSheetManager runat="server"
</telerik:RadStyleSheetManager> 
<telerik:RadScriptManager ID="RadScriptManager1" runat="server"
</telerik:RadScriptManager> 
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"
    <ajaxsettings> 
        <telerik:AjaxSetting AjaxControlID="Timer1"
            <UpdatedControls> 
                <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> 
            </UpdatedControls> 
        </telerik:AjaxSetting> 
        <telerik:AjaxSetting AjaxControlID="RadGrid1"
            <UpdatedControls> 
                <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> 
            </UpdatedControls> 
        </telerik:AjaxSetting> 
    </ajaxsettings> 
</telerik:RadAjaxManager> 
 
<asp:Timer ID="Timer1" runat="server" Interval="5000" OnTick="Timer1_Tick"></asp:Timer> 
 
<telerik:RadGrid ID="RadGrid1" runat="server" GridLines="None" OnNeedDataSource="RadGrid1_NeedDataSource" 
    OnDetailTableDataBind="RadGrid1_DetailTableDataBind" Skin="Inox" AutoGenerateColumns="False"
    <mastertableview datakeynames="moduleId"
        <DetailTables> 
            <telerik:GridTableView DataKeyNames="childModuleId" Name="Dependencies" Width="80%" runat="server">                     
                <Columns> 
                    <telerik:GridBoundColumn  HeaderText="id" DataField="childModuleId" UniqueName="childModuleId" Visible="false"
                    </telerik:GridBoundColumn> 
                    <telerik:GridTemplateColumn HeaderText="Dependencies" UniqueName="childModuleSelected" 
                            ItemStyle-Width="10"
                            <ItemTemplate> 
                                <asp:CheckBox ID="childActivatedCheckBox" Checked='<%# Convert.ToBoolean(Eval("childModuleSelected")) %>' 
                                    runat="server" AutoPostBack="True" /> 
                            </ItemTemplate> 
                            <ItemStyle Width="10px"></ItemStyle> 
                        </telerik:GridTemplateColumn> 
                    <telerik:GridBoundColumn DataField="childModuleName" ItemStyle-Width="150" UniqueName="childModuleName"
                            <ItemStyle Width="150px"></ItemStyle> 
                        </telerik:GridBoundColumn> 
                </Columns> 
            </telerik:GridTableView> 
        </DetailTables>             
        <Columns> 
            <telerik:GridBoundColumn HeaderText="Id" DataField="moduleId" UniqueName="moduleId"
            </telerik:GridBoundColumn> 
            <telerik:GridTemplateColumn HeaderText="Selected" UniqueName="moduleSelected" ItemStyle-Width="10"
                    <ItemTemplate> 
                        <asp:CheckBox ID="activatedCheckBox" Checked='<%# Convert.ToBoolean(Eval("moduleSelected")) %>' 
                            runat="server" AutoPostBack="True" /> 
                    </ItemTemplate> 
                    <ItemStyle Width="10px"></ItemStyle> 
                </telerik:GridTemplateColumn> 
            <telerik:GridBoundColumn HeaderText="Module Name" ItemStyle-Width="250" DataField="moduleName"
              <ItemStyle Width="250px"></ItemStyle> 
            </telerik:GridBoundColumn> 
        </Columns> 
    </mastertableview> 
</telerik:RadGrid> 


Code behind :

protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) 
    if (!e.IsFromDetailTable) 
    { 
        DataTable modulesTable = new DataTable(); 
        modulesTable.Columns.Add("moduleSelected"typeofbool )); 
        modulesTable.Columns.Add("moduleId"typeofint )); 
        modulesTable.Columns.Add("moduleName"typeofstring )); 
 
        Random r = new Random(123456); 
        forint i = 0; i < 10; i++ ) 
        { 
            int nId = r.Next(0, 10); 
 
            // USE IsPostBack properties to see if the grid is correctly rebinded 
            modulesTable.Rows.Add(IsPostBack, nId, "Module " + nId);                                 
        } 
 
        RadGrid1.DataSource = modulesTable; 
    } 
 
 
protected void RadGrid1_DetailTableDataBind(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e) 
    GridDataItem parentDataItem = (GridDataItem)e.DetailTableView.ParentItem; 
    int nParentModuleId = (int)parentDataItem.GetDataKeyValue("moduleId"); 
 
    DataTable dependenciesTable = new DataTable(); 
    dependenciesTable.Columns.Add("childModuleSelected"typeof(bool)); 
    dependenciesTable.Columns.Add("childModuleId"typeof(int)); 
    dependenciesTable.Columns.Add("childModuleName"typeof(string)); 
 
    Random r = new Random(123456); 
    for (int i = 0; i < 3; i++) 
    { 
        int nId = r.Next(0, 10); 
        dependenciesTable.Rows.Add(false, nId, "Module " + nId); 
    } 
 
    e.DetailTableView.DataSource = dependenciesTable;        
 
protected void Timer1_Tick(object sender, EventArgs e) 
    RadGrid1.Rebind(); 
 

Thanks in advance.

1 Answer, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 13 Oct 2008, 06:30 AM
Hi bronv,

To see more information along the lines of the requested functionality, please refer to the following article.
I hope this helps.

Sincerely yours,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
fredn
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Share this question
or