tags:

views:

467

answers:

3

Hello!

I am creating a web interface which currently reads data in from an XML data file, parses it into an array of Objects, after which I bind it to the data source of a Gridview. I then use and to retrieve the data I want from the objects for each column.

However, I am at the point that I would like to have multiple tabs in this gridview, possibly controlled by different link buttons. Each tab would show a different set of columns.

What would be the best way to implement this? Do I need to have three separate GridViews in my page, and just show the one for which the user selected (based on the click to the link button), while hiding all the others? This seemed like it might be unnecessarily slow. Is it possible to do via one GridView?

Right now the entire GridView is contained in an AJAX update panel, with the code below:

<asp:Panel id="searchResultsGrid" runat="server" CssClass="searchResultsGrid">
    <asp:GridView id="gridViewSearchResults" runat="server" AutoGenerateColumns="false" 
                    AllowPaging="True" AllowSorting="True" 
                    PageSize="25" Width="920" PagerSettings-Visible="false">
    <Columns>
        <asp:templatefield headertext="Test Column 1 Tab 1" HeaderStyle-HorizontalAlign="Left">
            <itemtemplate>
                <%# GetColumnInfo() %>
            </itemtemplate>
        </asp:templatefield>
        <asp:templatefield headertext="Test Column 2 Tab 1" HeaderStyle-HorizontalAlign="Left">
            <itemtemplate>
                <%# GetColumnInfo() %>
            </itemtemplate>
        </asp:templatefield>
        <asp:templatefield headertext="Test Column 3 Tab 1" HeaderStyle-HorizontalAlign="Left">
            <itemtemplate>
                <%# GetColumnInfo() %>
            </itemtemplate>
        </asp:templatefield>
        <asp:templatefield headertext="Test Column 4 Tab 1" HeaderStyle-HorizontalAlign="Right" ItemStyle-HorizontalAlign="Right">
            <itemtemplate>
                <%# GetColumnInfo() %>
            </itemtemplate>
        </asp:templatefield>
        <asp:templatefield headertext="Test Column 5 Tab 1" HeaderStyle-HorizontalAlign="Right" ItemStyle-HorizontalAlign="Right">
            <itemtemplate>
                <%# GetColumnInfo() %>
            </itemtemplate>
        </asp:templatefield>
        <asp:templatefield headertext="Test Column 6 Tab 1" HeaderStyle-HorizontalAlign="Right" ItemStyle-HorizontalAlign="Right">
            <itemtemplate>
                <%# GetColumnInfo() %>
            </itemtemplate>
        </asp:templatefield>
        <asp:templatefield headertext="Test Column 7 Tab 1" HeaderStyle-HorizontalAlign="Right" ItemStyle-HorizontalAlign="Right">
            <itemtemplate>
                <%# GetColumnInfo() %>
            </itemtemplate>
        </asp:templatefield>                            
    </Columns>
    <RowStyle CssClass="searchResultEntry borderTopGrey" />   
    <EmptyDataTemplate>
        <p class="searchResultsEmpty">
            <asp:Label ID="lblSearchResultsEmpty" runat="server" Text="No records matched the selected criteria.  Please revise your criteria and try again." CssClass="searchResultsEmpty"></asp:Label>
        </p>
    </EmptyDataTemplate>       
    </asp:GridView>
</asp:Panel>

This is the code I currently have for one gridview, with the content of one tab. Based on jdk's response, how would I go about adding other TemplateFields for the second and third tabs, and then switching between displaying the different sets when a tab link button is clicked?

Thanks!

+1  A: 

The page ViewState string can become very (unnecessarily) large when multiple GridViews are present (view its resulting HTML source code and search for "__VIEWSTATE" to see it). You can use one GridView control, like you said, and swap appropriate data into it depending on which LinkButton (a.k.a. "tab") was recently clicked.

If this is also a paginated data scenario, you can store a simple array of three integers in ViewState representing the current page number of each of the three sets of data, so you can display the most recent page of data when swapping them in and out of the one DataGrid control.

However if bandwidth is not a concern (i.e. if the page doesn't receive a lot of hits or runs on an Intranet) then don't worry as much about optimizing it.

John K
As far as AJAX is concerned, its presence shouldn't have a large effect on the bandwidth of your solution because the entirety of the server-side page is always run, and only the refresh area on the client side is updated - which presumably contains the largeness of all the DataGrids we're discussing here. The caveat is with AJAX enabled, while debugging, when you view the HTML source code, you will not see it change - it will sit at its initial state. Turn AJAX off (Page.ScriptManager.EnablePartialRendering=false) to test your solution with as little frustration as possible.
John K
Updated the question with some code, how would I add more template columns and tab between them like you suggest? Is there a property on the TemplateField I can set so that later I only bind (and show) those columns when doing the DataBind()?
kazzamalla
A: 

I've done similar things before. I used template columns for the GridView. And put a Ajax control toolkit tab control in the GridView.

sean717
A: 

I would probably create a Custom Composite Control (as the tabbed-container) and add the grid-view to that. I would not bundle it into one.

CodeMonkey