?
Solved

Datagrid columns are jumbled up when there are no rows (ASP.NET C#)

Posted on 2009-12-21
13
Medium Priority
?
300 Views
Last Modified: 2012-05-08
Hi,

I have a datagrid whose column headings appear together without any space when there are no rows in the datagrid.

Column heading appears fine when there are rows.

How to ensure proper spacing in column heading when there are NO rows?

Please check attached PPT for details.

Thanks!
Datagrid-columns-issue.ppt
0
Comment
Question by:meetpd
  • 4
  • 3
  • 3
  • +1
13 Comments
 
LVL 61

Expert Comment

by:HainKurt
ID: 26102111
where is the code for your datagrid?
0
 
LVL 61

Expert Comment

by:HainKurt
ID: 26102120
put it into a div

<div>
<asp:datagrid width="100%"...>
</div>

and you are good...
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 26102172
can you share your html - aspx code for datagrid
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 15

Expert Comment

by:rajeeshmca
ID: 26102354
HI meetpd,

Try giving the exact width for Header Cells in the datagrid
0
 

Author Comment

by:meetpd
ID: 26102423
Here' the grid code.
<asp:DataGrid ID="dgUsers" runat="server" AutoGenerateColumns="False" GridLines="None"
                    BorderWidth="0px" CellPadding="2" Width="100%" PageSize="15" OnItemCommand="dgUsers_ItemCommand"
                    OnItemDataBound="dgUsers_ItemDataBound" Height="48px" 
                    OnSelectedIndexChanged="dgUsers_SelectedIndexChanged" AllowSorting="True">
                    <ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
                        Font-Underline="False" HorizontalAlign="Left"></ItemStyle>
                    <HeaderStyle BackColor="#D0D0D0" ForeColor="DimGray" Font-Bold="True" Height="25px"
                        HorizontalAlign="Left" Font-Italic="False" Font-Overline="False" Font-Size="8pt" Font-Strikeout="False" Font-Underline="False" Font-Names="Arial"></HeaderStyle>
                    <Columns>
                        <asp:TemplateColumn HeaderText="No." Visible="False">
                            <HeaderStyle Width="1%" HorizontalAlign="Center" />
                            <ItemStyle HorizontalAlign="Center" Width="0%" />
                            <ItemTemplate>
                                <%# (dgUsers.PageSize * dgUsers.CurrentPageIndex) + Container.ItemIndex + 1%>
                            </ItemTemplate>
                        </asp:TemplateColumn>
                        <asp:BoundColumn DataField="FirstName" HeaderText="Full Name">
                            <ItemStyle HorizontalAlign="Left" Width="30%" Font-Bold="False" 
                                Font-Italic="False" Font-Overline="False" Font-Size="10pt" 
                                Font-Strikeout="False" Font-Underline="False" />
                            <HeaderStyle Width="1%" Font-Bold="True" Font-Italic="False" 
                                Font-Overline="False" Font-Size="10pt" Font-Strikeout="False" 
                                Font-Underline="False" />
                        </asp:BoundColumn>
                        <asp:BoundColumn DataField="MiddleName" HeaderText="Middle Name" 
                            Visible="False">
                            <HeaderStyle Font-Bold="True" Font-Italic="False" Font-Overline="False" 
                                Font-Size="10pt" Font-Strikeout="False" Font-Underline="False" />
                        </asp:BoundColumn>
                        <asp:BoundColumn DataField="SurName" HeaderText="Last Name" Visible="False">
                        </asp:BoundColumn>
                        
                        <asp:BoundColumn DataField="PAN" HeaderText="PAN No" DataFormatString="{0:N}">
                            <ItemStyle HorizontalAlign="Left" Width="30%" Font-Bold="False" 
                                Font-Italic="False" Font-Overline="False" Font-Size="10pt" 
                                Font-Strikeout="False" Font-Underline="False" />
                            <HeaderStyle HorizontalAlign="Left" Width="2%" BackColor="#D0D0D0" 
                                Font-Bold="True" Font-Italic="False" Font-Overline="False" 
                                Font-Strikeout="False" Font-Underline="False" ForeColor="DimGray" 
                                Font-Size="10pt" />
                        </asp:BoundColumn>
                         
                        <asp:BoundColumn DataField="Year" HeaderText="Fin. Year">
                            <HeaderStyle BackColor="#D0D0D0" Font-Bold="True" Font-Italic="False" 
                                Font-Overline="False" Font-Strikeout="False" Font-Underline="False" 
                                ForeColor="DimGray" HorizontalAlign="Left" Width="12%" Font-Size="10pt" />
                            <ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" 
                                Font-Size="10pt" Font-Strikeout="False" Font-Underline="False" 
                                HorizontalAlign="Left" />
                        </asp:BoundColumn>
                        <asp:BoundColumn>
                            <HeaderStyle Width="1%" />
                        </asp:BoundColumn>
                         
                        <asp:TemplateColumn>
                            <HeaderStyle Width="10%" HorizontalAlign="Left" Font-Bold="False" 
                                Font-Italic="False" Font-Overline="False" Font-Strikeout="False" 
                                Font-Underline="False" Wrap="False" />
                            <ItemTemplate>
                                                                  
                                <asp:LinkButton ID="imgEdit1" runat="server" CausesValidation="False" CommandName="Edit"
                                    Font-Names="Arial" Font-Size="10pt" Font-Bold="False" 
                                    ForeColor="DodgerBlue" CssClass="style12" >Start</asp:LinkButton>
                               
                                 <span class="style2">&nbsp;</span><span class="style7">|</span>&nbsp;<span class="style2"> </span>
                               
                                <asp:LinkButton ID="imgDelete1" runat="server"  CausesValidation="False" CommandName="Delete"
                                    Font-Names="Arial" Font-Size="8pt" ForeColor="DodgerBlue" 
                                    OnClick="imgDelete1_Click" Visible="False">Delete</asp:LinkButton>
                            </ItemTemplate>
                            <ItemStyle HorizontalAlign="Center" Width="10%" Font-Bold="False" 
                                Font-Italic="False" Font-Overline="False" Font-Size="10pt" 
                                Font-Strikeout="False" Font-Underline="False" Wrap="False" />
                        </asp:TemplateColumn>
                    </Columns>
                    <PagerStyle VerticalAlign="Middle" Height="20px" HorizontalAlign="Right" ForeColor="Black"
                        BackColor="LightGray" PageButtonCount="5" CssClass="nt1" Mode="NumericPages"
                        Font-Size="10pt"></PagerStyle>
                    <AlternatingItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False"
                        Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Left" />
                </asp:DataGrid>

Open in new window

0
 

Author Comment

by:meetpd
ID: 26102430
Dear HainKurt,

Width is already 100% for datagrid. Still it did not work :(
0
 

Author Comment

by:meetpd
ID: 26102436
And yeah, I also put it in a div...with no positive results.
0
 
LVL 15

Expert Comment

by:rajeeshmca
ID: 26102447
Did you give the width for each and every cell
0
 
LVL 15

Expert Comment

by:rajeeshmca
ID: 26102448
Header cell
0
 
LVL 61

Expert Comment

by:HainKurt
ID: 26102454
try this

<div style="width:100%">
<asp:datgrid width-"100%".../>
</div>

do you have a link

or try this

<div style="width:800">
<asp:datgrid width="100%" .../>
</div>

or just try thuis

<asp:datgrid width=800 .../>
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 26102461
try this
<asp:DataGrid ID="dgUsers" runat="server" AutoGenerateColumns="False" GridLines="None"
                    BorderWidth="0px" CellPadding="2" Width="100%" PageSize="15" OnItemCommand="dgUsers_ItemCommand"
                    OnItemDataBound="dgUsers_ItemDataBound" Height="48px" 
                    OnSelectedIndexChanged="dgUsers_SelectedIndexChanged" AllowSorting="True">
                    <ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
                        Font-Underline="False" HorizontalAlign="Left"></ItemStyle>
                    <HeaderStyle BackColor="#D0D0D0" ForeColor="DimGray" Font-Bold="True" Height="25px"
                        HorizontalAlign="Left" Font-Italic="False" Font-Overline="False" Font-Size="8pt" Font-Strikeout="False" Font-Underline="False" Font-Names="Arial"></HeaderStyle>
                    <Columns>
                        <asp:TemplateColumn HeaderText="No." Visible="False">
                            <HeaderStyle Width="1%" HorizontalAlign="Center" />
                            <ItemStyle HorizontalAlign="Center" Width="0%" />
                            <ItemTemplate>
                                <%# (dgUsers.PageSize * dgUsers.CurrentPageIndex) + Container.ItemIndex + 1%>
                            </ItemTemplate>
                        </asp:TemplateColumn>
                        <asp:BoundColumn DataField="FirstName" HeaderText="Full Name">
                            <ItemStyle HorizontalAlign="Left" Width="30%" Font-Bold="False" 
                                Font-Italic="False" Font-Overline="False" Font-Size="10pt" 
                                Font-Strikeout="False" Font-Underline="False" />
                            <HeaderStyle Width="30%" Font-Bold="True" Font-Italic="False" 
                                Font-Overline="False" Font-Size="10pt" Font-Strikeout="False" 
                                Font-Underline="False" />
                        </asp:BoundColumn>
                        <asp:BoundColumn DataField="MiddleName" HeaderText="Middle Name" 
                            Visible="False">
                            <HeaderStyle Font-Bold="True" Font-Italic="False" Font-Overline="False" 
                                Font-Size="10pt" Font-Strikeout="False" Font-Underline="False" />
                        </asp:BoundColumn>
                        <asp:BoundColumn DataField="SurName" HeaderText="Last Name" Visible="False">
                        </asp:BoundColumn>
                        
                        <asp:BoundColumn DataField="PAN" HeaderText="PAN No" DataFormatString="{0:N}">
                            <ItemStyle HorizontalAlign="Left" Width="30%" Font-Bold="False" 
                                Font-Italic="False" Font-Overline="False" Font-Size="10pt" 
                                Font-Strikeout="False" Font-Underline="False" />
                            <HeaderStyle HorizontalAlign="Left" Width="30%" BackColor="#D0D0D0" 
                                Font-Bold="True" Font-Italic="False" Font-Overline="False" 
                                Font-Strikeout="False" Font-Underline="False" ForeColor="DimGray" 
                                Font-Size="10pt" />
                        </asp:BoundColumn>
                         
                        <asp:BoundColumn DataField="Year" HeaderText="Fin. Year">
                            <HeaderStyle BackColor="#D0D0D0" Font-Bold="True" Font-Italic="False" 
                                Font-Overline="False" Font-Strikeout="False" Font-Underline="False" 
                                ForeColor="DimGray" HorizontalAlign="Left" Width="12%" Font-Size="10pt" />
                            <ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" 
                                Font-Size="10pt" Font-Strikeout="False" Font-Underline="False" 
                                HorizontalAlign="Left" />
                        </asp:BoundColumn>
                        <asp:BoundColumn>
                            <HeaderStyle Width="1%" />
                        </asp:BoundColumn>
                         
                        <asp:TemplateColumn>
                            <HeaderStyle Width="10%" HorizontalAlign="Left" Font-Bold="False" 
                                Font-Italic="False" Font-Overline="False" Font-Strikeout="False" 
                                Font-Underline="False" Wrap="False" />
                            <ItemTemplate>
                                                                  
                                <asp:LinkButton ID="imgEdit1" runat="server" CausesValidation="False" CommandName="Edit"
                                    Font-Names="Arial" Font-Size="10pt" Font-Bold="False" 
                                    ForeColor="DodgerBlue" CssClass="style12" >Start</asp:LinkButton>
                               
                                 <span class="style2">&nbsp;</span><span class="style7">|</span>&nbsp;<span class="style2"> </span>
                               
                                <asp:LinkButton ID="imgDelete1" runat="server"  CausesValidation="False" CommandName="Delete"
                                    Font-Names="Arial" Font-Size="8pt" ForeColor="DodgerBlue" 
                                    OnClick="imgDelete1_Click" Visible="False">Delete</asp:LinkButton>
                            </ItemTemplate>
                            <ItemStyle HorizontalAlign="Center" Width="10%" Font-Bold="False" 
                                Font-Italic="False" Font-Overline="False" Font-Size="10pt" 
                                Font-Strikeout="False" Font-Underline="False" Wrap="False" />
                        </asp:TemplateColumn>
                    </Columns>
                    <PagerStyle VerticalAlign="Middle" Height="20px" HorizontalAlign="Right" ForeColor="Black"
                        BackColor="LightGray" PageButtonCount="5" CssClass="nt1" Mode="NumericPages"
                        Font-Size="10pt"></PagerStyle>
                    <AlternatingItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False"
                        Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Left" />
                </asp:DataGrid>

Open in new window

0
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 2000 total points
ID: 26102466
What I have changed is  .. changed the width of Header in follwoing columns

  <asp:BoundColumn DataField="FirstName" HeaderText="Full Name">
                            <ItemStyle HorizontalAlign="Left" Width="30%" Font-Bold="False"
                                Font-Italic="False" Font-Overline="False" Font-Size="10pt"
                                Font-Strikeout="False" Font-Underline="False" />
                            <HeaderStyle Width="30%" Font-Bold="True" Font-Italic="False"
                                Font-Overline="False" Font-Size="10pt" Font-Strikeout="False"
                                Font-Underline="False" />
                        </asp:BoundColumn>


 <asp:BoundColumn DataField="PAN" HeaderText="PAN No" DataFormatString="{0:N}">
                            <ItemStyle HorizontalAlign="Left" Width="30%" Font-Bold="False"
                                Font-Italic="False" Font-Overline="False" Font-Size="10pt"
                                Font-Strikeout="False" Font-Underline="False" />
                            <HeaderStyle HorizontalAlign="Left" Width="30%" BackColor="#D0D0D0"
                                Font-Bold="True" Font-Italic="False" Font-Overline="False"
                                Font-Strikeout="False" Font-Underline="False" ForeColor="DimGray"
                                Font-Size="10pt" />
                        </asp:BoundColumn>
0
 

Author Comment

by:meetpd
ID: 26102526
Thanks a ton Pratima_mcs, it worked!

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Loops Section Overview
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

839 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