tags:

views:

102

answers:

3

    <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  A: 

Try something like this:

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

where 50px is the width you need.

Andrew Hare
This works but it's expanding all fields. I only need to expand "ComputerModel" a specific field. Is there a way?
Kombucha
Make sure that you are setting this attribute on the BoundField itself and not accidentally on the GridView.
Andrew Hare
+1  A: 

Try this:

<asp:BoundField DataField="ComputerModel" HeaderText="ComputerModel" 
        SortExpression="ComputerModel" 
        HeaderStyle-Width="50px" >
</asp:BoundField>
Canavar
This works but it's expanding all the columns. I only need to expand "ComputerModel" a specific field.
Kombucha
Are you sure ? I tried it and it works well. As you can see, we're defining only one column's width.
Canavar
I know and understand that. I am defining 1 field only but then all the 9 fields seems to be affected by: HeaderStyle-Width="50px" >.I might be doing wrong.
Kombucha
<asp:BoundField DataField="PCRecId" HeaderText="PCRecId" InsertVisible="False" ReadOnly="True" SortExpression="PCRecId" /><asp:BoundField DataField="EmpNum" HeaderText="EmpNum" SortExpression="EmpNum" /><asp:BoundField DataField="Location" HeaderText="Location" SortExpression="Location" /> <asp:BoundField DataField="ComputerModel" HeaderText="ComputerModel" SortExpression="ComputerModel" HeaderStyle-Width="50px" /> // HERE IS THE FIELD<asp:CheckBoxField DataField="Lease" HeaderText="Lease" SortExpression="Lease" />
Kombucha
I don't understand why this happens, maybe you're setting gridview's headerstyle-with too as Andrew said ? or can you try to set HeaderStyle-BackColor="Aqua" and see if the only one column effected ? Can you increase the width to 200px for example to see the effect ?
Canavar
This works: HeaderStyle-BackColor="Aqua" - only one column effected.BUT NOT THIS: HeaderStyle-Width="200px".
Kombucha
A: 

Can we see all the HTML for the control? I'm curious to see the markup for the entire control so I don't make any assumptions.

Per MSDN try

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

I would like to see what you have thus far and maybe I can be more helpful. Also is there any CSS class that may be setting the item width?

Hcabnettek
<asp:BoundField DataField="ComputerModel" HeaderText="ComputerModel" SortExpression="ComputerModel" ItemStyle-Width="50px"/>
Kombucha
That's only one field. I need to see the WHOLE control please. Thanks
Hcabnettek
see above please.
Kombucha
Unfortunately that is DEFINITELY NOT the whole control so we cannot help you. You keep providing the databound fields within the control, so we cannot see the whole control. If you do decide to post the control, perhaps we can help. Until then, good luck.
Hcabnettek