Solved

Gridview Item Template width

Posted on 2011-03-06
4
883 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

763 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

6 Experts available now in Live!

Get 1:1 Help Now