[英]Can not set ASP.Net Gridview Template Column width to 0
In a asp.net grid view I have add a TemplateColumn and I need to set its width to 0, Even if I set it in HTML code or code behind when it displayed it in browser it has a width. 在asp.net网格视图中,我添加了一个TemplateColumn,我需要将其宽度设置为0,即使我在HTML代码或代码中设置它,当它在浏览器中显示时它有一个宽度。 How to solve this?
怎么解决这个?
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>
Output HTML 输出HTML
Output 产量
Set the font size of the data within the column to 0, hope this works.. thanks 将列中数据的字体大小设置为0,希望这有效..谢谢
<asp:BoundField DataField="CommID" Visible="true" ItemStyle-ForeColor="White"
HeaderText="" ItemStyle-Width="0px" ControlStyle-Width="0px" ItemStyle-Font-Size="0" >
below solution worked for me - 1. create below css 以下解决方案为我工作 - 1.创建下面的CSS
<style>
.hidden { display: none;}
</style>
Modify your TemplateField as below 修改您的TemplateField,如下所示
< asp:TemplateField HeaderText=""> <asp:TemplateField HeaderText =“”>
< HeaderStyle CssClass="hidden" Width="0px" /> <HeaderStyle CssClass =“hidden”Width =“0px”/>
< ItemStyle CssClass="hidden" Width="0px" /> <ItemStyle CssClass =“hidden”Width =“0px”/>
< ItemTemplate> < asp:HiddenField ID="IDVal" runat="server" Value='<%# Eval("UserID") %>' /> <ItemTemplate> <asp:HiddenField ID =“IDVal”runat =“server”Value ='<%#Eval(“UserID”)%>'/>
< /ItemTemplate> </ ItemTemplate>
< /asp:TemplateField> </ asp:TemplateField>
Hope this helps. 希望这可以帮助。 Thanks
谢谢
i tried with ItemStyle-Width="0px" ControlStyle-Width="0px"
but it showing small column. 我尝试使用
ItemStyle-Width="0px" ControlStyle-Width="0px"
但它显示的是小列。 then i try with Visible="false"
then the column is not visible but the problem is when we try to get cell text in code behind, it shows "". 然后我尝试使用
Visible="false"
然后该列不可见,但问题是当我们尝试在代码中获取单元格文本时,它显示“”。
my solution: 我的解决方案
set GridView1.Columns(2).Visible = False
设置
GridView1.Columns(2).Visible = False
if you want to read data from that column then 如果你想从那一列读取数据
GridView1.Columns(2).Visible = True
If GridView1.Rows(1).Cells(2).Text ="abc" Then
'do somthing......
GridView1.Columns(2).Visible = False
My advise is that you make the column invisible (set Visible="false"
) and you define the property that you are binding on that column as one of the DataKeyNames on your grid; 我的建议是你使列不可见(设置
Visible="false"
)并将你在该列上绑定的属性定义为网格上的DataKeyNames之一; that way, you'll be able to retrieve it whenever you want. 这样,你就可以随时检索它。
for example: 例如:
<asp:gridview DataKeyNames="PropertyYouNeed,ID,SomethingElse" ... />
Then when you post back, you can get the data from the GridView.DataKeys property 然后,当您回发时,您可以从GridView.DataKeys属性获取数据
I found TemplateColumn
HeaderText
is automatically set to four spaces (automatically generated), setting the HeaderText
to one space from UI fixed the problem. 我发现
TemplateColumn
HeaderText
自动设置为四个空格(自动生成),将HeaderText
设置为从UI固定问题的一个空格。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.