Solved

Gridview columns width

Posted on 2011-03-03
6
559 Views
Last Modified: 2012-05-11
I am trying to increase the width size of the columns on my gridview, but  iam having troubles having it done, can you please review my code and see if I am doing anything wrong?
asp.net part

  <asp:gridview ID="Gridview1" runat="server" ShowFooter="True" 
            AutoGenerateColumns="False" onrowcreated="Gridview1_RowCreated" 
            EnableModelValidation="True" CssClass = "GridViewStyle" HeaderStyle-CssClass ="HeaderStyle" 
            RowStyle-CssClass ="RowStyle" AlternatingRowStyle-CssClass = "AltRowStyle"  >
            
            <Columns>
         
            <asp:BoundField DataField="RowNumber" HeaderText="Row Number" ControlStyle-CssClass="wide" />
            <asp:TemplateField ControlStyle-CssClass="wide" >
               <HeaderTemplate  >
               <asp:Label runat="server">NT-1</asp:Label>
            
            <asp:TextBox ID="txt_Census1" runat="server" Width="30px" ></asp:TextBox>
            </HeaderTemplate>


                <ItemTemplate>
                    Bed:
                    <asp:TextBox ID="txt_Bed1" runat="server" Width="30px"></asp:TextBox>
                    Status:
                    <asp:DropDownList ID="txt_Comment1" runat="server" AppendDataBoundItems="True" 
                    style="text-align: left" >
                    <asp:ListItem value="0" text="Select">  </asp:ListItem>
                    <asp:ListItem>Assigned</asp:ListItem>
                    <asp:ListItem>BR</asp:ListItem>
                    <asp:ListItem>Open NS</asp:ListItem>
                                      
                </asp:DropDownList>

                </ItemTemplate>
            </asp:TemplateField>





css


/**  * GRIDVIEW STYLES  **/

/* Css Class - Whole Table */ 

.GridViewStyle{font-family: Arial, Sans-Serif; 
font-size:small; 
table-layout: auto; 
border-collapse: collapse; 
border: #1d1d1d 1px solid; 
width: 300px;

} 

.HeaderStyle th{ 
Padding : 5px; 
Color : #C0C0C0;
width: 300px;
} 


/*Apply padding and color to header of <th> in table */
.HeaderStyle 
{ 
background-image: url(Images/HeaderChromeBlack.jpg); 
background-position:center; 
background-repeat:repeat-x; 
background-color:#1d1d1d; 
    width: 300px;

} 


.RowStyle td
{
    background-color: #c9c9c9;
    width: 300px;
} 

/*Alternate rows will be shaded */

.AltRowStyle td 
{ 
padding: 5px; 
border-right :solid 1px #1d1d1d; 
width: 300px;
} 


input.wide { width: 100px; }

Open in new window

0
Comment
Question by:TonyReba
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 9

Expert Comment

by:gdupadhyay
ID: 35028200

You need to update the CSS.

See this URL to set the GV columns width

http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_21767971.html

Or you can set the dynamic columns width

http://msdn.microsoft.com/en-us/library/ms178296.aspx
0
 
LVL 9

Expert Comment

by:gdupadhyay
ID: 35028211
In CSS, update below according to your requirement.:

.GridViewStyle{font-family: Arial, Sans-Serif;
font-size:small;
table-layout: auto;
border-collapse: collapse;
border: #1d1d1d 1px solid;
width: 300px;

}

0
 
LVL 9

Author Comment

by:TonyReba
ID: 35028308
I dont see any chnage on the css you provided?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Author Comment

by:TonyReba
ID: 35028325
I just need to width for the entire column be increased,  no matter if is a static width
0
 
LVL 8

Expert Comment

by:Anurag Agarwal
ID: 35028467
pls try this


<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
            <Columns>
                <asp:BoundField HeaderText="Name">
                    <ItemStyle Width="500px" />
                </asp:BoundField>
                <asp:BoundField HeaderText="Description">
                    <ItemStyle Width="1000px" />
                </asp:BoundField>
            </Columns>
 </asp:GridView>

and refer to gridview column width
0
 
LVL 9

Accepted Solution

by:
gdupadhyay earned 500 total points
ID: 35028661
I just posted the CSS part need to update.
In your CSS, Please update
width: 300px; to width: 500px; or width: 600px; according to your requirement.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
In this Micro Tutorial viewers will learn how to create a CSS image sprite (In a later tutorial, viewers will learn how to use CSS and HTML to create a navigation menu using this sprite) Open a new Photoshop document with a width of (Icon width)x(N…
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…

730 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