在C#中创建一个选项卡式Gridview [英] Creating a tabbed Gridview in C#

查看:219
本文介绍了在C#中创建一个选项卡式Gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个Web接口,该接口当前从XML数据文件中读取数据,将其解析为对象数组,然后将其绑定到Gridview的数据源。然后,我使用并从每个列的对象中检索我想要的数据。



然而,我希望在这个gridview中有多个选项卡,可能由不同的链接按钮控制。每个标签都会显示一组不同的列。



执行此操作的最佳方法是什么?我是否需要在页面中有三个独立的GridView,并且只显示用户选择的一个(基于点击链接按钮),同时隐藏所有其他的?这看起来似乎可能会不必要的缓慢。是否可以通过一个GridView完成?



现在整个GridView都包含在AJAX更新面板中,代码如下:

 < asp:Panel id =searchResultsGridrunat =serverCssClass =searchResultsGrid> 
< asp:GridView id =gridViewSearchResultsrunat =serverAutoGenerateColumns =false
AllowPaging =TrueAllowSorting =True
PageSize =25Width = 920PagerSettings-Visible =false>
<列>
< asp:templatefield headertext =Test Column 1 Tab 1HeaderStyle-Horizo​​ntalAlign =Left>
< itemtemplate>
<%#GetColumnInfo()%>
< / itemtemplate>
< / asp:templatefield>
< asp:templatefield headertext =Test Column 2 Tab 1HeaderStyle-Horizo​​ntalAlign =Left>
< itemtemplate>
<%#GetColumnInfo()%>
< / itemtemplate>
< / asp:templatefield>
< asp:templatefield headertext =Test Column 3 Tab 1HeaderStyle-Horizo​​ntalAlign =Left>
< itemtemplate>
<%#GetColumnInfo()%>
< / itemtemplate>
< / asp:templatefield>
< asp:templatefield headertext =Test Column 4 Tab 1HeaderStyle-Horizo​​ntalAlign =RightItemStyle-Horizo​​ntalAlign =Right>
< itemtemplate>
<%#GetColumnInfo()%>
< / itemtemplate>
< / asp:templatefield>
< asp:templatefield headertext =Test Column 5 Tab 1HeaderStyle-Horizo​​ntalAlign =RightItemStyle-Horizo​​ntalAlign =Right>
< itemtemplate>
<%#GetColumnInfo()%>
< / itemtemplate>
< / asp:templatefield>
< asp:templatefield headertext =Test Column 6 Tab 1HeaderStyle-Horizo​​ntalAlign =RightItemStyle-Horizo​​ntalAlign =Right>
< itemtemplate>
<%#GetColumnInfo()%>
< / itemtemplate>
< / asp:templatefield>
< asp:templatefield headertext =Test Column 7 Tab 1HeaderStyle-Horizo​​ntalAlign =RightItemStyle-Horizo​​ntalAlign =Right>
< itemtemplate>
<%#GetColumnInfo()%>
< / itemtemplate>
< / asp:templatefield>
< /列>
< RowStyle CssClass =searchResultEntry borderTopGrey/>
< EmptyDataTemplate>
< p class =searchResultsEmpty>
< asp:Label ID =lblSearchResultsEmptyrunat =serverText =没有记录符合所选标准,请修改您的标准并重试。的CssClass = searchResultsEmpty >< / ASP:标签>
< / p>
< / EmptyDataTemplate>
< / asp:GridView>
< / asp:面板>

这是我目前用于一个gridview的代码,其中包含一个选项卡的内容。基于jdk的响应,我将如何为第二个和第三个选项卡添加其他TemplateFields,然后在单击Tab键链接按钮时显示不同的集合之间进行切换?

感谢!

解决方案

当多个GridViews存在时,页面ViewState字符串可能变得非常(不必要)代码并搜索__VIEWSTATE以查看它)。您可以像您说的那样使用一个GridView控件,并根据最近点击哪个LinkBut​​ton(又名标签)来交换适当的数据。

如果这也是分页数据场景,则可以在ViewState中存储一个由三个整数组成的简单数组,表示三组数据中的每一个的当前页码您可以在将数据交换进一个DataGrid控件时显示最新的数据页面。



然而,如果带宽不是问题(即如果页面不' t可以在Intranet上得到很多点击或运行),那么不用担心优化它。


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!

解决方案

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.

这篇关于在C#中创建一个选项卡式Gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆