Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

ASP.net GridView TemplateField width

Hi

I am trying to widen my first template field to 600 as shown below but the field seems to                                   <HeaderStyle Width="600px" />
remain the same narrow size

            <asp:GridView ID="GridView_Questions" runat="server" BackColor="White"
                BorderColor="#3366CC" BorderStyle="Solid" BorderWidth="1px" CellPadding="4"
                Height="147px" Visible="False" Width="795px">
                <Columns>
       
                               <asp:TemplateField HeaderText="Question">

                               </asp:TemplateField>

I also tried the following which didn't work either
            <asp:GridView ID="GridView_Questions" runat="server" BackColor="White"
                BorderColor="#3366CC" BorderStyle="Solid" BorderWidth="1px" CellPadding="4"
                Height="147px" Visible="False" Width="795px">
                <Columns>
       
                               <asp:TemplateField HeaderText="Question" ControlStyle-Height="220"
            ControlStyle-Width="700">
                                   <ControlStyle Height="220px" Width="700px" />
                                   <HeaderStyle HorizontalAlign="Left" />

                               </asp:TemplateField>
Avatar of Jerry Miller
Jerry Miller
Flag of United States of America image

What you are doing should probably work, but I set the theme for my gridviews in a .skin file that work for me.

<asp:GridView CellPadding="5" AutoGenerateColumns="False" GridLines="Horizontal" runat="server" BorderColor="Black"
        BorderStyle="Solid" BorderWidth="1" ForeColor="#333333" Font-Names="Verdana"
        EnableSortingAndPagingCallbacks="True" AllowPaging="True" AllowSorting="True" >
    <PagerSettings Position="TopAndBottom" PageButtonCount="20" />
    <RowStyle BackColor="#ffffff" BorderStyle="Solid" BorderWidth="1px" BorderColor="Black" Font-Size="10px" />
    <AlternatingRowStyle BackColor="#e8e8e8" HorizontalAlign="Left" />
    <FooterStyle BackColor="#6699FF" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="White" ForeColor="Black" Font-Bold="True" />
    <HeaderStyle BackColor="#DCEDE5" ForeColor="Black" Font-Size="10px"/>
    <FooterStyle BackColor="#DCEDE5" ForeColor="Black" Font-Size="11px" Font-Bold="True"/>
    <EditRowStyle BackColor="#FFFF99" ForeColor="Black" Font-Bold="True" />
    <EmptyDataTemplate>
        <center> -- No Records Found -- </center>
    </EmptyDataTemplate>
</asp:GridView>

However I have a few properties in my CSS file that didn't seem to work in the .skin file:

.gridview
      {
            font-size:0.75em;
            width:90%;
      }
      
      .gridview tr
      {
            font-size:0.95em;
            height:auto;
      }
      
      .gridview td
      {
            font-size:1.15em;
      }
      .gridview caption
      {
            text-align:left;
            font-size:0.85em;
            font-weight:bold;
            font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
            padding: 2px;
            color:Black;
            background-color: #DCEDE5;
            border:solid 1px black;
      }
A couple of other things I have in my .skin file for gridviews:

<asp:GridView SkinId="NoEmptyTemplate" CellPadding="5" AutoGenerateColumns="False" GridLines="Horizontal" runat="server" BorderColor="Black"
        BorderStyle="Solid" BorderWidth="1" ForeColor="#333333" Font-Names="Verdana"
        EnableSortingAndPagingCallbacks="True" AllowPaging="True" AllowSorting="True">
    <PagerSettings Position="TopAndBottom" PageButtonCount="20" />
    <RowStyle BackColor="#ffffff" BorderStyle="Solid" BorderWidth="1px" BorderColor="Black" Font-Size="10px" />
    <AlternatingRowStyle BackColor="#e8e8e8" HorizontalAlign="Left" />
    <FooterStyle BackColor="#6699FF" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="White" ForeColor="Black" Font-Bold="True" />
    <HeaderStyle BackColor="#DCEDE5" ForeColor="Black" Font-Size="10px"/>
    <FooterStyle BackColor="#DCEDE5" ForeColor="Black" Font-Size="11px" Font-Bold="True"/>
    <EditRowStyle BackColor="#FFFF99" ForeColor="Black" Font-Bold="True" />
 </asp:GridView>

<asp:GridView SkinID="noAlternateRows" CellPadding="5" AutoGenerateColumns="False" GridLines="Horizontal" runat="server" BorderColor="Black"
        BorderStyle="Solid" BorderWidth="1" ForeColor="#333333" Font-Names="Verdana"
        EnableSortingAndPagingCallbacks="True" AllowPaging="True" AllowSorting="True">
    <PagerSettings Position="TopAndBottom" PageButtonCount="20" />
    <RowStyle BackColor="#ffffff" BorderStyle="Solid" BorderWidth="1px" BorderColor="Black" Font-Size="10px" />
    <FooterStyle BackColor="#6699FF" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="White" ForeColor="Black" Font-Bold="True" />
    <HeaderStyle BackColor="#DCEDE5" ForeColor="Black" Font-Size="10px"/>
    <FooterStyle BackColor="#DCEDE5" ForeColor="Black" Font-Size="11px" Font-Bold="True"/>
    <EditRowStyle BackColor="#FFFF99" ForeColor="Black" Font-Bold="True" />
    <EmptyDataTemplate>
        <center> -- No Records Found -- </center>
    </EmptyDataTemplate>
</asp:GridView>
ASKER CERTIFIED SOLUTION
Avatar of Jerry Miller
Jerry Miller
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Murray Brown

ASKER

Thanks very much