Solved

Gridview Item Template width

Posted on 2011-03-06
4
891 Views
Last Modified: 2012-05-11
Can someone how can I define an static width  for a gridview so the bound objects doesnt auto increase the width of the cells, ( Iam planning to have a fixed size of character on the textboxes)

Will this be done in CSS?



<asp:gridview ID="Gridview2" runat="server" ShowFooter="True" 
            AutoGenerateColumns="False" onrowcreated="Gridview2_RowCreated" 
            EnableModelValidation="True">
            
            <Columns>
         
            <asp:BoundField DataField="RowNumber" HeaderText="Row Number" />
            <asp:TemplateField >
               <HeaderTemplate  >
               <asp:Label ID="Label2" runat="server">NT-1</asp:Label>
            
            <asp:TextBox ID="txt_Census19" runat="server" Width="50px" ></asp:TextBox>
            </HeaderTemplate>


                <ItemTemplate>
                    Bed:
                    <asp:TextBox ID="txt_Bed19" runat="server" Width="50px"></asp:TextBox>
                    Status:
                    <asp:DropDownList ID="txt_Comment19" runat="server" AppendDataBoundItems="True" 
                    style="text-align: left" >
                    <asp:ListItem value="0" text="Select">  </asp:ListItem>
                    <asp:ListItem>Assigned</asp:ListItem>
                    <asp:ListItem>Blocked Room</asp:ListItem>
                    <asp:ListItem>Open NS</asp:ListItem>
                                      
                </asp:DropDownList>

                </ItemTemplate>
            </asp:TemplateField>

Open in new window

0
Comment
Question by:TonyReba
  • 2
4 Comments
 
LVL 13

Expert Comment

by:agarwalrahul
ID: 35051973
Use Code:

 <asp:BoundField HeaderText="Header Text" DataField="Datafield" SortExpression="Datafield">
                                <ItemStyle HorizontalAlign="Center" width="50px"  />
                                <HeaderStyle cssclass="myGridHeader"  HorizontalAlign="Center"  ForeColor="White" />
                            </asp:BoundField>
0
 
LVL 13

Expert Comment

by:agarwalrahul
ID: 35052032
For Template Field Column Use Code:

<asp:TemplateField >
               <HeaderTemplate  >
               <asp:Label ID="Label2" runat="server">NT-1</asp:Label>
               <asp:TextBox ID="txt_Census19" runat="server" Width="50px" ></asp:TextBox>
            </HeaderTemplate>
                <ItemTemplate>
                                <ItemStyle HorizontalAlign="Center" width="50px"  />
                                <HeaderStyle cssclass="myGridHeader"  HorizontalAlign="Center"  ForeColor="White" />
                           </ItemTemplate>
            </asp:TemplateField>
0
 
LVL 9

Author Comment

by:TonyReba
ID: 35056216
Could I do this with css , and defining this property on the Gridview only?
0
 
LVL 7

Accepted Solution

by:
mr_nadger earned 500 total points
ID: 35068184
this is my CSS for gridviews, set cssclass=mgrid in the gridview's properties, and the rest is inherited.

.mGrid {    
    background-color: #fff;    
    margin: 5px 0 10px 0;    
    border: solid 1px #525252;    
    border-collapse:collapse;  
    vertical-align:top;
    font-size: 12px;
    font-family: Arial, Sans-Serif;
}  
.mGrid td {    
    padding: 2px;    
    border: solid 1px #c1c1c1;    
    color: #717171;  
    vertical-align:top;
}  
.mGrid th {    
    color: White;    
    background: #5078B3 ;    
    font-size: 12px;
    font-family: Arial, Sans-Serif;
    text-align:center;  
}  


you can set the width in the .mGrid td section, but this will likely override any settings within the grid's own properties
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

821 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