WebHierarchicalDataGrid - get selected rows on the Server

Alex Kartavov / Friday, October 29, 2010

This sample shows how to get all selected rows in a WebHierarchicalDataGrid on the server using recursion:

    protected void Page_Load(object sender, EventArgs e)

    {

        this.WebHierarchicalDataGrid1.DataSource = CreateDataSet();

    }

 

    protected void button_click(object sender, EventArgs e)

    {

        selection.InnerHtml = "";

        GetContainerGrid(WebHierarchicalDataGrid1.GridView);

    }

 

    protected void GetContainerGrid(ContainerGrid gridView)

    {

        if (gridView.Level == 0)

            GetSelectedRows(gridView);

 

        for (int i = 0; i < gridView.Rows.Count; i++)

        {

            ContainerGridRecord record = (ContainerGridRecord)gridView.Rows[i];

 

            if (record.HasRowIslands)

            {

                ContainerGrid containerGrid = record.RowIslands[0];

                GetSelectedRows(containerGrid);

                GetContainerGrid(containerGrid);

            }

        }

    }

    protected void GetSelectedRows(ContainerGrid gridView)

    {

 

        SelectedRowCollection rows = gridView.Behaviors.Selection.SelectedRows;

        for (int i = 0; i < rows.Count; i++)

        {

            if (gridView.Level == 0)

                selection.InnerHtml += rows[i].Items[1].Text + "<br/>";

            else

                selection.InnerHtml += rows[i].Items[2].Text + "<br/>";

        }

    }

Enjoy!

ASP.NET team

ServerSideSelection.zip