Solved

Gridview Item Template width

Posted on 2011-03-06
4
890 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

810 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