【问题标题】:Can not set ASP.Net Gridview Template Column width to 0无法将 ASP.Net Gridview 模板列宽设置为 0
【发布时间】:2011-11-14 04:46:31
【问题描述】:

在 asp.net 网格视图中,我添加了一个 TemplateColumn,我需要将其宽度设置为 0,即使我在 HTML 代码或代码后面设置它,当它在浏览器中显示时它也有一个宽度。如何解决?

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

输出

【问题讨论】:

  • 你不让它可见 = false.......有什么共鸣吗?
  • @Pranay 是的,不能将其可见性设置为 false,因为我正在做一些棘手的事情(根据本教程 codeproject.com/KB/aspnet/Drill_down_Datagrid.aspx)。需要将其宽度设置为 0,但其内容显示在 gridview 的其他位置。

标签: c# asp.net visual-studio gridview


【解决方案1】:

将列内数据的字体大小设置为0,希望这能工作..谢谢

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

【讨论】:

    【解决方案2】:

    我的建议是使列不可见(设置Visible="false")并将绑定在该列上的属性定义为网格上的DataKeyNames之一;这样,您就可以随时检索它。

    例如:

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

    那么当你回帖时,你可以从GridView.DataKeys property获取数据

    【讨论】:

      【解决方案3】:

      我发现TemplateColumn HeaderText 自动设置为四个空格(自动生成),将HeaderText 从 UI 设置为一个空格修复了问题。

      【讨论】:

        【解决方案4】:

        以下解决方案对我有用 - 1.在css下面创建

        <style>
            .hidden { display: none;}
        </style>
        
        1. 如下修改你的 TemplateField






        希望这会有所帮助。谢谢

        【讨论】:

          【解决方案5】:

          我尝试使用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
          

          【讨论】:

            猜你喜欢
            • 2015-11-23
            • 2017-06-21
            • 1970-01-01
            • 1970-01-01
            • 2020-11-28
            • 2017-09-13
            • 2012-01-06
            • 2023-03-29
            • 1970-01-01
            相关资源
            最近更新 更多