Solved

Gridview columns width

Posted on 2011-03-03
6
553 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
  • 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
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.

 
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

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

Suggested Solutions

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…
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
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 a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

911 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

20 Experts available now in Live!

Get 1:1 Help Now