如何显示和隐藏内部GridView列

时间:2016-08-14 05:51:31

标签: c# asp.net gridview abstract

我有一个带有一个嵌套GridView的GridView,如下所示:

<asp:GridView ID="gvEmpNew" runat="server" AutoGenerateColumns="false" BackColor="White"
                                    BorderColor="#E9ECEF" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" ShowFooter="true"
                                    GridLines="None" EmptyDataText="There are no data records to display." OnRowDataBound="gvEduTrainingExp_RowDataBound"
                                    Width="970px">
                                    <Columns>
                                       <asp:TemplateField ItemStyle-CssClass="gridViewCellCenter" HeaderStyle-CssClass="headerStyle" >
                                            <ItemTemplate>
                                                <a href="javascript:expandcollapse('div<%# Eval("empid") %>', 'two');"> 
                                                    <img id="imgdiv<%# Eval("empid") %>" alt="Click to show/hide Details for Education Information <%# Eval("empid") %>"
                                                        width="15px" border="0" src="../images/plus.gif" title="Education" />
                                                </a>
                                            </ItemTemplate>
                                        </asp:TemplateField>

                                        <asp:TemplateField ItemStyle-CssClass="gridViewCellCenter" HeaderStyle-CssClass="headerStyle" >
                                            <ItemTemplate>
                                               <div></div>
                                            </ItemTemplate>
                                        </asp:TemplateField>
<asp:TemplateField>
                                            <ItemTemplate>
                                                <tr>
                                                    <td colspan="100%">
                                                        <div id="div<%# Eval("empid") %>" style="display:none; position: relative;
                                                            left: 10px; width: 100%"> 
<asp:GridView ID="GridViewChildEducation" runat="server" AutoGenerateColumns="False" 
                                                                BackColor="White" BorderColor="#E9ECEF" BorderStyle="None" BorderWidth="1px"
                                                                CellPadding="4" ForeColor="Black" GridLines="None" EmptyDataText="">
                                                                <Columns>

                                                                    <asp:TemplateField HeaderText="EXAM TITLE">
                                                                        <ItemTemplate>
                                                                            <asp:Label ID="lblEXAM_TITLE" runat="server" Text='<%# Eval("EXAM_TITLE") %>'></asp:Label>
                                                                        </ItemTemplate>
                                                                    </asp:TemplateField>

                                                                    <asp:TemplateField HeaderText="EDUCATION LEVE LNAME" >
                                                                        <ItemTemplate>
                                                                            <asp:Label ID="lblEDUCATIONLEVELNAMEChild" runat="server" Text='<%# Eval("EDUCATIONLEVELNAME") %>'></asp:Label>
                                                                        </ItemTemplate>
                                                                    </asp:TemplateField>
</Columns>
                                                                <HeaderStyle CssClass="headerStyle" />
                                                                <RowStyle CssClass="rowStyle" />
                                                                <AlternatingRowStyle CssClass="alternatingRowStyle" />
                                                            </asp:GridView>
</Columns>
                                    <HeaderStyle CssClass="headerStyle" />
                                    <RowStyle CssClass="rowStyle" />
                                    <AlternatingRowStyle CssClass="alternatingRowStyle" />
                                </asp:GridView>

我想隐藏一个名为GridViewChildEducation的GridView。我试过这段代码:

GridViewChildEducation.Columns[1].Visible = false;

它向我显示当前上下文中不存在名称GridViewChildEducation。我需要一种方法来隐藏或显示这个'GridViewChildEducation'GridView

的任何列

1 个答案:

答案 0 :(得分:0)

你无法使用: GridViewChildEducation.Style.Visibility =&#34;隐藏&#34 ;; GridViewChildEducation.Style.Display =&#34;无&#34 ;;

或为一个CSS类创建隐藏,一个用于可见,然后走那条路。

但是,我有点困惑 - 你只是试图隐藏一列或整个视图吗?