Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to specify specific width to specific column and heading
please tell me i want to specify FIX width of any address or name
which property i should use
ASP.NET
<asp:GridView ID="grdsearch" runat="server" AutoGenerateColumns="False" 
                            onrowcreated="grdsearch_RowCreated"  
                            onrowdeleting="grdsearch_RowDeleting" DataKeyNames="cust_id" 
                            Width="750px">
                            <Columns>
                                <asp:BoundField DataField="cust_id" HeaderText="Customer Id" 
                                    ItemStyle-Width="200px"  ItemStyle-VerticalAlign="Middle" >
                            
                                <ItemStyle VerticalAlign="Middle" Width="200px" />
                            
                                </asp:BoundField>
                                <asp:BoundField DataField="cust_name" HeaderText="Customer Name" 
                                    ItemStyle-Width="200px"  ItemStyle-VerticalAlign="Middle" >
                               
                                <HeaderStyle Width="30%" />
                               
                                <ItemStyle VerticalAlign="Middle" Width="40%" />
                               
                                </asp:BoundField>
                                <asp:BoundField DataField="cust_address" HeaderText="Address"  
                                    ItemStyle-Width="200px"  ItemStyle-VerticalAlign="Middle" >
                               
                                <HeaderStyle Width="500px" />
                               
                                <ItemStyle VerticalAlign="Middle" Width="700px" Wrap="False" />
                               
                                </asp:BoundField>
                                <asp:BoundField DataField="cust_city" HeaderText="City" ItemStyle-Width="200px"  
                                    ItemStyle-VerticalAlign="Middle" >
                               
                                <ItemStyle VerticalAlign="Middle" Width="200px" />
                               
                                </asp:BoundField>
                                <asp:BoundField DataField="cust_telephone" HeaderText="Telephone"  
                                    ItemStyle-Width="200px"  ItemStyle-VerticalAlign="Middle" >
                              
                                <ItemStyle VerticalAlign="Middle" Width="200px" />
                              
                                </asp:BoundField>
                                <asp:BoundField DataField="cust_email" HeaderText="Email Id" />
                                <asp:BoundField DataField="sales_contact_prsn" 
                                    HeaderText="Sales Contact Person" />
                                <asp:BoundField DataField="sales_mob_no" HeaderText="Sales Mobile Number" />
                                  <asp:CommandField ShowDeleteButton="True" ButtonType="Button" 
                                    HeaderText="Delete" />
                            </Columns>
                          
                            <RowStyle Wrap="False" BorderWidth="10px" />
                          
                            <SelectedRowStyle CssClass="grdselectback" />
                        </asp:GridView>
Posted
Comments
n.podbielski 5-Nov-12 6:31am    
So itemstyle verticalalign="Middle" width="200px" is not working?

Using Following Templates we can Specify Width;
or You can Provide Css Class to Them for Fix Width.
XML
<FooterStyle Width="112px" />                                                                                    <HeaderStyle Width="112px" />                                                                                    <ItemStyle Width="112px" />

Kaushik
 
Share this answer
 
v3
Hi,

I had a similar problem and looking at the gridview defination,
If i sum all the widths if your gridview columns,it goes beyond the width of your grid.

Check changing the width of the grid after summing up all your column widths.

Hope this helps.
 
Share this answer
 
For each column add the below line of code and Specify each column Width.
XML
ItemStyle-Width="5%" ItemStyle-Wrap="true"

Make sure that sum of all columns width should be equal to width of GridView.

Hope this will help you...
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900