如何在GridView中制作一个特定的字段?
问题描述:
<asp:BoundField DataField="ComputerModel" HeaderText="ComputerModel"
SortExpression="ComputerModel"
ItemStyle-Width="50px"/>
<asp:CheckBoxField DataField="Lease" HeaderText="Lease"
SortExpression="Lease" />
<asp:BoundField DataField="SerialNumber" HeaderText="SerialNumber"
SortExpression="SerialNumber" />
<asp:BoundField DataField="LeasedTagNum" HeaderText="LeasedTagNum"
SortExpression="LeasedTagNum" />
<asp:BoundField DataField="MonitorType" HeaderText="MonitorType"
SortExpression="MonitorType" />
<asp:BoundField DataField="MonitorCount" HeaderText="MonitorCount"
SortExpression="MonitorCount" />
<asp:CommandField ShowEditButton="True" ShowInsertButton="True" />
</Fields>
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
答
尝试是这样的:
<asp:BoundField DataField="ComputerModel" ItemStyle-Width="50px"/>
其中50px
是你所需要的宽度。
答
试试这个:
<asp:BoundField DataField="ComputerModel" HeaderText="ComputerModel"
SortExpression="ComputerModel"
HeaderStyle-Width="50px" >
</asp:BoundField>
+0
这可行,但它扩大了所有的列。我只需要扩展“ComputerModel”一个特定的领域。 – Yves 2009-07-15 19:27:26
答
我们可以看到所有控件的HTML?我很好奇看到整个控件的标记,所以我不做任何假设。
每MSDN尝试
<asp:boundfield
sortexpression="LastName"
datafield="LastName"
headertext="LastName">
<itemstyle width="50px">
</itemstyle>
</asp:boundfield>
我想看看你有什么迄今,也许我可以提供更多的帮助。还有没有可能设置项目宽度的任何CSS类?
这可以工作,但它扩大了所有领域。我只需要扩展“ComputerModel”一个特定的领域。有没有办法? – Yves 2009-07-15 19:29:41
确保您在BoundField本身上设置了此属性,而不是无意中在GridView上设置此属性。 – 2009-07-15 19:37:36