簡體   English   中英

如何隱藏datagridview的第一列添加仍獲取數據

[英]How to hide first column of datagridview add still get data

我想用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中實現,則可以嘗試以下操作

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;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM