2011-11-14 29 views
0

在asp.net網格視圖中,我添加了一個TemplateColumn,我需要將其寬度設置爲0,即使我將它設置爲HTML代碼或代碼後面在瀏覽器中顯示它有一個寬度。如何解決這個問題?無法設置ASP.Net Gridview模板列寬爲0

HTML

<asp:TemplateField Visible="False" ControlStyle-Width="0"> 
      <HeaderStyle BorderWidth="0" Width="0"></HeaderStyle> 
      <ItemStyle BorderWidth="0" Width="0"></ItemStyle> 
      <FooterStyle BorderWidth="0" Width="0"></FooterStyle> 
      <ItemTemplate> 
       <itemstyle width="0" /> 
       <asp:PlaceHolder ID="ExpandedContent" Visible="false" runat="server"></td> </tr> 
        <tr> 
         <td class="label" colspan="2" align="left"> 
        Test</asp:PlaceHolder> 
       </td> </tr> 
      </ItemTemplate> 
      <FooterStyle BorderWidth="0px" Width="0px" /> 
     </asp:TemplateField> 

輸出HTML

output

輸出

enter image description here

+0

Ÿ不要你使其可見=假.......有任何共振? –

+0

@Pranay是的,無法將其可見性設置爲false,因爲我在做一些棘手的事情(根據本教程http://www.codeproject.com/KB/aspnet/Drill_down_Datagrid.aspx)。需要將其寬度設置爲0,但其內容顯示在gridview中的其他位置。 – Nalaka526

回答

0

我發現TemplateColumnHeaderText被自動設置爲四個空格(自動生成)的數據,設置HeaderText從UI到一個空間解決了這個問題。

enter image description here

0

我的建議是,你使列不可見(設置Visible="false"),你定義你在該列上你的網格的DataKeyNames的一個結合的財產;這樣,你就可以隨時檢索它。

例如:

<asp:gridview DataKeyNames="PropertyYouNeed,ID,SomethingElse" ... /> 

然後,當你回來後,你可以從GridView.DataKeys property

2

設置列中數據的字體大小爲0,希望這個作品..謝謝

<asp:BoundField DataField="CommID" Visible="true" ItemStyle-ForeColor="White" 
      HeaderText="" ItemStyle-Width="0px" ControlStyle-Width="0px" ItemStyle-Font-Size="0" > 
0

以下解決方案爲我 - 1.創建下面的CSS

<style> 
    .hidden { display: none;} 
</style> 
  1. 修改您的TemplateField,如下所示

    < ASP:模板列的HeaderText = 「」>
    < HeaderStyle的CssClass = 「隱藏」 WIDTH = 「0像素」/>
    < ItemStyle的CssClass = 「隱藏」 WIDTH = 「0像素」/>
    <的ItemTemplate> < ASP:HiddenField ID = 「IDVal」 RUNAT = 「服務器」 值= '<%#的eval( 「用戶ID」)%>'/>
    </ItemTemplate中>
    </ASP:的TemplateField>

希望這會有所幫助。謝謝

0

我試過ItemStyle-Width="0px" ControlStyle-Width="0px",但它顯示小列。然後我嘗試Visible="false"然後列不可見,但問題是當我們嘗試獲取代碼中的單元格文本後,它顯示「」。

我的解決方案:

設置GridView1.Columns(2).Visible = False

,如果你想讀從列數據,然後

GridView1.Columns(2).Visible = True 

If GridView1.Rows(1).Cells(2).Text ="abc" Then 
     'do somthing...... 

GridView1.Columns(2).Visible = False