Click here to Skip to main content
15,895,831 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear all

I want to width for every TemplateField in gridview
Is it possible ? If yes please revert
else
please tell me other solution for the same.

thanks..................
Posted

To set the column width for GridView, you can use the <HeaderStyle> or <ItemStyle> to set witdth for a template column.

Sample:
XML
<asp:TemplateField HeaderText="used" SortExpression="used">
<HeaderStyle Width="100" />
<ItemStyle Width="100" />

<HeaderTemplate>
fjsfjkldsfksdjfdsfjfkksfsdkfdsjfjkfdsj
</HeaderTemplate>

<EditItemTemplate>
......
......


Details here: MSDN: Tutorial 12: Using TemplateFields in the GridView Control[^]
 
Share this answer
 
Comments
Member 7894579 27-May-13 5:35am    
thanks
Member 11123172 31-Oct-14 7:54am    
thanks for code project
you can set the width here is a simple example

XML
<asp:TemplateField>
                                                <ItemStyle Width="7%" BorderColor="Dodgerblue" BackColor="white" HorizontalAlign="Left"/>
 
Share this answer
 
use ItemStyle-Width (ItemStyle-*)
 
Share this answer
 
try in this way.

XML
<asp:TemplateField HeaderText="Name">
    <ItemTemplate>
           <asp:Label ID="lblCatId" runat="server" Text='<%#Eval("CatId") %>'></asp:Label>
    </ItemTemplate>
    <ItemStyle Width="20%" />
   </asp:TemplateField>
 
Share this answer
 
v2
if i click addnew linkbutton. i need to get empty row in the gridview.
 
Share this answer
 

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