2009-07-15 155 views
0

如何在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" /> 

回答

3

嘗試是這樣的:

<asp:BoundField DataField="ComputerModel" ItemStyle-Width="50px"/> 

其中50px是你所需要的寬度。

+0

這可以工作,但它擴大了所有領域。我只需要擴展「ComputerModel」一個特定的領域。有沒有辦法? – Yves 2009-07-15 19:29:41

+0

確保您在BoundField本身上設置了此屬性,而不是無意中在GridView上設置此屬性。 – 2009-07-15 19:37:36

1

試試這個:

<asp:BoundField DataField="ComputerModel" HeaderText="ComputerModel" 
     SortExpression="ComputerModel" 
     HeaderStyle-Width="50px" > 
</asp:BoundField> 
+0

這可行,但它擴大了所有的列。我只需要擴展「ComputerModel」一個特定的領域。 – Yves 2009-07-15 19:27:26

0

我們可以看到所有控件的HTML?我很好奇看到整個控件的標記,所以我不做任何假設。

每MSDN嘗試

<asp:boundfield 
     sortexpression="LastName" 
     datafield="LastName" 
     headertext="LastName"> 
      <itemstyle width="50px"> 
      </itemstyle> 
     </asp:boundfield> 

我想看看你有什麼迄今,也許我可以提供更多的幫助。還有沒有可能設置項目寬度的任何CSS類?

相關問題