【问题标题】:How to hide first column of datagridview add still get data如何隐藏datagridview的第一列添加仍然获取数据
【发布时间】:2019-11-01 14:32:04
【问题描述】:

我想用 css 隐藏我的 gridview 的第一列,但没有成功。

这是生成的 html 的一部分。

<table class="mGrid" cellspacing="0" cellpadding="3" rules="all" ridlines="None" border="1" id="PageContent_gvLocation" style="border-collapse:collapse;">
        <tbody><tr>
            <th scope="col"><a href="javascript:__doPostBack('ctl00$PageContent$gvLocation','Sort$ubicacion_componente_id')">ubicacion id</a></th><th scope="col"><a href="javascript:__doPostBack('ctl00$PageContent$gvLocation','Sort$armario')">Armario</a></th><th scope="col"><a href="javascript:__doPostBack('ctl00$PageContent$gvLocation','Sort$cajon')">Cajon</a></th><th scope="col">&nbsp;</th>
        </tr><tr>
            <td>
                            <span id="PageContent_gvLocation_lblLocationID_0" class="gridTextbox">46</span>
                        </td><td>
                            <span id="PageContent_gvLocation_lblCloset_0" class="gridTextbox">testarmariio</span>
                        </td><td>                       
                            <span id="PageContent_gvLocation_lblDrawer_0" class="gridTextbox">testcajon</span>
                        </td><td>
                            <input type="image" name="ctl00$PageContent$gvLocation$ctl02$ctl00" title="Edit" src="../Images/edit.png" style="height:20px;width:20px;">
                            <input type="image" name="ctl00$PageContent$gvLocation$ctl02$ctl01" title="Delete" src="../Images/delete.png" style="height:20px;width:20px;">
                        </td>
        </tr><tr class="alt">
            <td>

这是我的 asp.net 代码。

  <asp:GridView ID="gvLocation" runat="server" AutoGenerateColumns="false" ShowFooter="true" 
            ShowHeaderWhenEmpty="true" AllowPaging="True" OnPageIndexChanging="gvLocation_PageIndexChanging"
            OnRowEditing="gvLocation_RowEditing" OnRowCancelingEdit="gvLocation_RowCancelingEdit"
            AllowSorting="true" onsorting="gvLocation_Sorting" ridLines="None" CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt" CellPadding="3">
            <%-- Theme Properties --%>
            <Columns>  
                <asp:TemplateField HeaderText="ubicacion id" SortExpression="ubicacion_componente_id">
                    <ItemTemplate>
                        <asp:Label CssClass="gridTextbox" ID="lblLocationID"  Text='<%# Eval("ubicacion_componente_id") %>' runat="server" />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox CssClass="gridTextbox" ID="txtLocationID" Text='<%# Eval("ubicacion_componente_id") %>' runat="server" />
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox CssClass="gridTextbox" ID="txtLocationIDFooter" runat="server" />
                    </FooterTemplate>
                </asp:TemplateField>  
            </Columns>
        </asp:GridView>

如何使用 css 隐藏我的 gridview 的第一列。

【问题讨论】:

    标签: css asp.net gridview


    【解决方案1】:

    如果你想根据你的代码只用 CSS 实现,你可以尝试以下

    table.mGrid  tr td:first-child{
       display:none;
    }
    
    table.mGrid  tr th:first-child{
       display:none;
    } 
    

    分页器通常在最后一行可用,您始终可以选择排除表格的最后一行,使用以下代码:

    table.mGrid tr:not(:last-child) td:first-child {
        display: none;
    }
    
    table.mGrid tr:not(:last-child) th:first-child {
        display: none;
    }
    

    【讨论】:

    • 是的,一个 css 解决方案会很棒,但是当我使用你建议的 css 时,它会删除我的 gridview 底部的页码。
    • 请发布您生成的 html,包括寻呼机
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-13
    • 2013-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多