Hi,I'am using WebHierarchicalDataGrid and want to keep expanded on client side rows as expanded after postback.The scenario is following:1. The grid has several levels.2. User expands several rows on the client side and does a postback.3. After postback I want all expanded rows are remained expanded.
Is it possible? I've tried to go through all rows before databind method of grid is called and store "Expanded" state of each row. But each row has NOT Expanded = false . I think it is because EnableDataViewState="false" (default option)
Please help.
Alexander
Alexander,
The default behavior of the grid is to keep expanded states over postbacks so long as you do not call ClearDataSource() or RefreshBehaviors().
regards,David Young
Hello Alexander,
I was able to see that rows keep their expanded state by default on post back. I have used below mark up and code to test the behavior you described:
<ig:WebHierarchicalDataGrid ID="WebHierarchicalDataGrid1" runat="server" Height="350px" Width="400px" DataKeyFields="ID" AutoGenerateBands="False" AutoGenerateColumns="False" InitialDataBindDepth="0"><Columns> <ig:BoundDataField DataFieldName="ID" Header-Text="ID" Key="ID"> </ig:BoundDataField><ig:BoundDataField DataFieldName="NumEditorID" Header-Text="NumEditorID" Key="NumEditorID" ></ig:BoundDataField></Columns><Bands><ig:Band DataMember="Locals" Key="Locals" AutoGenerateColumns="false" DataKeyFields="ModID"><Columns><ig:BoundDataField DataFieldName="ModID" Header-Text="ModID" Key="ModID" ></ig:BoundDataField></Columns></ig:Band></Bands></ig:WebHierarchicalDataGrid>
protected void Page_Load(object sender, EventArgs e){if (Session["data"] == null){Session["data"] = GetEmployDepartmentDataSet();}this.WebHierarchicalDataGrid1.DataSource = Session["data"];}private DataSet GetEmployDepartmentDataSet(){DataSet ds = new DataSet("EmployeeRecords");// Get the tables to use in the DataSetDataTable Employees = new DataTable("Employess");Employees.Columns.Add("ID", typeof(int));Employees.Columns.Add("NumEditorID", typeof(int));for (int i = 0; i < 10; i++){Employees.Rows.Add(new object[] { i, i+i });}Employees.PrimaryKey = new DataColumn[] { Employees.Columns[0] };DataTable Locals = new DataTable("Locals");Locals.Columns.Add("ModID", typeof(int));for (int i = 0; i < 10; i++){Locals.Rows.Add(new object[] { i});}Locals.PrimaryKey = new DataColumn[] { Locals.Columns[0] };// Add the tables to the DataSetds.Tables.Add(Employees);ds.Tables.Add(Locals);// Create the relationship between the tables.ds.Relations.Add("DepartmentEmployee", Employees.Columns["ID"], Locals.Columns["ModID"]);return ds;}
However, you may write below lines of code that will keep the state of expanded grid:
if (this.WebHierarchicalDataGrid1.GridView.Rows.Count > 0){foreach (ContainerGridRecord rec in this.WebHierarchicalDataGrid1.GridView.Rows){if (rec.Expanded == true){ rec.ExpandChildren(); }}}
I hope this helps.