1

I am working on an asp.net page. In which I am using a grid view. I want to be able to change the width of the bound fields. I am using ControlStyle-Width="100px" and itemstyle-width but I unable to change width of bound field. Can anyone tell me how this could be done?

  <asp:BoundField DataField="ptDob" HeaderText="PatientDob" HeaderStyle-HorizontalAlign="Left" SortExpression="ptDob" ControlStyle-Width="2500px"  />
                <asp:BoundField DataField="memid" HeaderText="MemberId" HeaderStyle-HorizontalAlign="Left"  ControlStyle-Width="100px"
                    SortExpression="memid" />
                <asp:BoundField DataField="memssn" HeaderText="MembeSsn" HeaderStyle-HorizontalAlign="Left"  ItemStyle-Width="100px"
                    SortExpression="memssn" />
                <asp:BoundField DataField="billType" HeaderText="BillType" HeaderStyle-HorizontalAlign="Left"  ItemStyle-Width="100px"
                    SortExpression="billType" />
                <asp:BoundField DataField="insuranceName" HeaderText="insuranceName" HeaderStyle-HorizontalAlign="Left"  ItemStyle-Width="100px"
                    SortExpression="insuranceName" />
                <asp:BoundField DataField="taxId" HeaderText="TaxId" HeaderStyle-HorizontalAlign="Left"  ItemStyle-Width="100px"
                    SortExpression="taxId" />
                <asp:BoundField DataField="attendingProvider" HeaderText="AttendingProvider" HeaderStyle-HorizontalAlign="Left"  ItemStyle-Width="100px"
                    SortExpression="attendingProvider" />
                <asp:BoundField DataField="parStatus" HeaderText="parStatus" HeaderStyle-HorizontalAlign="Left"  ItemStyle-Width="100px"
                    SortExpression="parStatus" />
                <asp:BoundField DataField="admittedDate" HeaderText="AdmittedDate" HeaderStyle-HorizontalAlign="Left"
                    SortExpression="admittedDate" />
                <asp:BoundField DataField="billedAmount" HeaderText="BilledAmount" HeaderStyle-HorizontalAlign="Left"
Kevin Kunderman
  • 2,036
  • 1
  • 19
  • 30
srihari
  • 917
  • 4
  • 14
  • 26

3 Answers3

1

ItemStyle-Width="100px" or HeaderStyle-Width="100px" should perfectly work, maybe you have some other style interfering, CSS maybe.

EmmanuelRC
  • 348
  • 1
  • 6
  • This fails if the table isn't already wider than the sum of all the columns. If the overall table is narrow, these widths will be ignored and the fields "squished" down to their minimum text size. `min-width` can be used instead in the generated `td`, see here: http://stackoverflow.com/questions/14765817/why-does-css-td-width-not-work However, I don't see a way to manipulate that style on a `BoundField`. (`CssClass` can be used to control this, but requires writing separate page style) – ebyrob Mar 10 '17 at 15:29
1

You can add it as a CSS field in your itemstyle. Then make sure the class has a width set. Assuming you've not got any inline styles that take precedence then this will work.

<asp:BoundField DataField="parStatus" HeaderText="parStatus">
    <ItemStyle CssClass="yourclass"></ItemStyle>
</asp:BoundField>
Full Time Skeleton
  • 1,680
  • 1
  • 22
  • 39
  • Note: You'd want to set the css style `min-width` not `width` to work correctly for the resulting `td` element. – ebyrob Mar 10 '17 at 15:28
0

Try Using HeaderText-cssClass, in class add

padding-left: 100px;
padding-right: 100px;