Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Gridview columns width

Posted on 2011-03-03
6
Medium Priority
?
562 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
Technology Partners: 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

When writing CSS, there are a few simple rules that will make your life easier.    1. Using ‘* {box-sizing:border-box;}’. Using this will wrap all your elements in a nice little compact box-model that will give you the width you want, like so... …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
Suggested Courses

705 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