Solved

ASP.net GridView TemplateField width

Posted on 2014-01-06
4
884 Views
Last Modified: 2014-01-06
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>
0
Comment
Question by:murbro
  • 3
4 Comments
 
LVL 18

Expert Comment

by:Jerry Miller
ID: 39759286
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;
      }
0
 
LVL 18

Expert Comment

by:Jerry Miller
ID: 39759290
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>
0
 
LVL 18

Accepted Solution

by:
Jerry Miller earned 500 total points
ID: 39759292
I also set individual template fields using CSS as well.
0
 

Author Closing Comment

by:murbro
ID: 39759426
Thanks very much
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now