Link to home
Start Free TrialLog in
Avatar of TonyReba
TonyRebaFlag for United States of America

asked on

Gridview Item Template width

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

Avatar of Rahul Agarwal
Rahul Agarwal
Flag of India image

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>
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>
Avatar of TonyReba

ASKER

Could I do this with css , and defining this property on the Gridview only?
ASKER CERTIFIED SOLUTION
Avatar of mr_nadger
mr_nadger
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial