Solved

ASP.net GridView TemplateField width

Posted on 2014-01-06
4
899 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

896 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

13 Experts available now in Live!

Get 1:1 Help Now