Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using a gridview of 10 columns .so its appearing in the page with horizontal scroll bar.I want to reduce the column width of the grid view.i am using tamplate field for the grid view column.please help.
Posted

C#
<asp:templatefield headertext="" >
<headerstyle width="50" />
<itemstyle width="50" />
........
.......
......
.....
</asp:templatefield>

Regards..:laugh:
 
Share this answer
 
v2
Comments
Soumya 2 25-Jul-13 1:45am    
i have tried this but not working :( my code is
<asp:TemplateField HeaderText="ProjectName" >
<HeaderStyle Width="50" />
<itemstyle width="50">
<edititemtemplate>
<asp:TextBox ID="txtProjectName" runat="server" Width="100" Height="150" TextMode="MultiLine" Text='<%# Bind("ProjectName") %>'>
<asp:RequiredFieldValidator ID="rfvProjectName" runat="server" ControlToValidate="txtProjectName" ErrorMessage="Please Provide Project Name" Text="Field Can't be blank" Display="Dynamic" >

<itemtemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("ProjectName") %>'>

<footertemplate>
<asp:TextBox ID="txtInsertProjectName" runat="server" Text='<%# Bind("ProjectName") %>'>

Thanks7872 25-Jul-13 1:47am    
Priority will be given to the control. So better you set itemstyle/headerstyle width and control width with same size.Hope it will work.
Use follwoing style , put listgrid class to gridview and remove all default style sheet applied to gridview.
and then you can play with widh of the header ,row etc
CSS
<style>
.listgrid
{
    border-collapse: collapse;
    width: 100%;
    border-top: 1px solid #DDDDDD;
    border-left: 1px solid #DDDDDD;
    margin-bottom: 20px;
}
.listgrid td
{
    border-right: 1px solid #DDDDDD;
    border-bottom: 1px solid #DDDDDD;

}
.listgrid th
{
    border-right: 1px solid #DDDDDD;
    border-bottom: 1px solid #DDDDDD;

}
.listgrid thead th
{
    background-color: #EFEFEF;
    padding: 7px;
}
.listgrid thead th a, .listgrid thead th
{
    text-decoration: none;
    color: #222222;
    font-weight: bold;
}
.listgrid tbody td a
{
    text-decoration: underline;
}
.listgrid tbody td
{
    vertical-align: middle;
    padding: 0px 5px;
    background: #FFFFFF;
    text-align: left;
    padding: 7px;
}
</style>
 
Share this answer
 
Comments
Soumya 2 25-Jul-13 1:55am    
I want to reduce the size of some specific columns..can u plz advice ???
kishore sharma 25-Jul-13 2:03am    
then use
<HeaderStyle Width="150px"></HeaderStyle>
for template field.
<asp:TemplateField Visible="false">
<HeaderStyle Width="150px"></HeaderStyle>
<HeaderTemplate>
<asp:Label ID="lblAll" runat="server">All
</HeaderTemplate>
<itemtemplate>
<asp:TextBox ID="txtID" runat="server" Text='<%# Eval("Id") %>' Enabled="false">

<itemstyle horizontalalign="Center">

and
<asp:BoundField HeaderText="SNo" DataField="Id" HeaderStyle-Width="40px">
<HeaderStyle Width="40px" />
</asp:BoundField>

for bound field
Soumya 2 25-Jul-13 2:08am    
as per u,I have tried this

<asp:TemplateField HeaderText="ITWRno" >
<HeaderStyle Width="50px" />
<edititemtemplate>
<asp:TextBox ID="TextBox1" runat="server" Height="100" Text='<%# Bind("ITWRno") %>'>

<itemtemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("ITWRno") %>'>

<footertemplate>
<asp:TextBox ID="txtInsertITWR" runat="server" Text='<%# Bind("ITWRno") %>'>



but not working :(
kishore sharma 25-Jul-13 2:12am    
did u applied style sheet class
Soumya 2 25-Jul-13 2:17am    
No i havent tried that one..

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