Skip to content Skip to sidebar Skip to footer

Datagrid Tree (two Levels) - Dynamically Generated Grids Cannot Be Altered

I am trying to implement a tree view datagrid with two levels. I am binding my data as follows: private void BindData() { string sqlQuery = 'SELECT dept_code, dept_name

Solution 1:

I did something like this by simply using a repeater with a datagrid in the item template.

based on either a click on the row in the repeater / a button on the row I would then "toggle" a panels visibility within the template that shows or hides the grid during that postback i would also databind the child grid ... so I only databind the visible grid and not all grids in all rows.

it looked something like this (sorry if its not spot on doing this from head ram):

<asp:Repeater ...>
  <ItemTemplate>
    <tr>
    <td> ... </td>
    <td>
       <asp:Panel ..>
          <asp:GridView ...>
             ...
          </asp:GridView>
       </asp:Panel>
    </td>
    </tr>
  </ItemTemplate>
</asp:Repeater>

On page load if !IsPostback bind the repeater. On Row events for items in the repeater rows: 1. Toggle panel visible for that row 2. get data 3. pass to grid within row. 4. databind grid

to get different views simply use different panels within the item template of the repeater.

seems to work well, and is pretty efficient.

Also: I have the child grid in a separate custom control to keep the code tidy and prevent massive reams of code in 1 code behind file.


Post a Comment for "Datagrid Tree (two Levels) - Dynamically Generated Grids Cannot Be Altered"