Click here to Skip to main content
11,642,216 members (67,213 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
good morning all
in gridview display,some of my data value is to lengthy,so in display,they are overwitten.
if i set the fixed width then if any data that will be inserted in future will be more then that width then problem will occur.
is there any solution???
another problem is that if there will be no data in my database means 0 record,then gridview will not be displayed.but i want my header to be displayed even if there is no record

------------------------------------------------------------------------------------
<div id="Div4" style="overflow-x: auto; width: 1207px;">
<asp:GridView ID="gvState" runat="server" CellPadding="10" CellSpacing="10" AutoGenerateColumns="False" AlternatingRowStyle-CssClass="alternate-row"
HeaderStyle-Height="50px" RowStyle-Height="30px" RowStyle-CssClass="table-product" OnRowUpdating="gvvendor_RowUpdating" OnRowCommand="gvvendor_rowcommand"
OnRowDeleting="gvvendor_rwdeleting" CssClass="grid_css" Visible="true" AllowPaging="true" OnPageIndexChanging="gvState_PageIndexChanging" DataKeyNames="ID">
<rowstyle cssclass="table-product" font-size="30px" height="30px" horizontalalign="Center" verticalalign="Middle">
 </rowstyle>
Posted 15-Nov-11 18:03pm
pal5hah618
Edited 15-Nov-11 18:07pm
uspatel30K
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try this one..I got the header when there is no record

 if (ds.Tables[0].Rows.Count == 0)
        {
            ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
            GridView1.DataSource = ds;
            GridView1.DataBind();
            int columncount = GridView1.Rows[0].Cells.Count;
            GridView1.Rows[0].Cells.Clear();
            GridView1.Rows[0].Cells.Add(new TableCell());
            GridView1.Rows[0].Cells[0].ColumnSpan = columncount;
            GridView1.Rows[0].Cells[0].Text = "No Records Found";
        }
        else
        {
            GridView1.DataSource = ds;
            GridView1.DataBind();
        }
  Permalink  
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

For the first problem you can use tool tip as solution and use fix width. so additional words display in tool tip. below i m show the way of writing the tool tip solution and hope you can edit it and customize it to your solution.

in OnRowDataBound event set the maximum length which fit to the column and other characters send to tool tip.
user this code inside onrowbound event
const int maxLength =10;
            if (obj.CompanyName.Length > maxLength)
            {
                ((Label)e.Row.FindControl("lblBindName")).Text = this.GetExtraWordsforToolTip(obj.CompanyName, maxLength);
 
            }

and extra words will display in tool tip.

private string GetExtraWordsforToolTip(string word, int wordMaxLenth)
    {
        string strDescription = @"<p><a class='tooltip' href='#'>" + text.Substring(0, maxLength - 7) + "(...)" + @"<span class='normal'>" + text + "</span></a></p> ";
        return strDescription;
    }






.tooltip
{
    border-bottom: 1px dotted #000000;
    color: #000000;
    outline: none;
    cursor: pointer;
    text-decoration: none;
    position: relative;
}
.tooltip span
{
    margin-left: -999em;
   position:absolute;
 

}
.tooltip:hover span
{
    border-radius: 5px 5px;
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.1);
    -webkit-box-shadow: 5px 5px rgba(0, 0, 0, 0.1);
    -moz-box-shadow: 5px 5px rgba(0, 0, 0, 0.1);
    font-family: Verdana,Calibri, Tahoma, sans-serif;
    position: absolute;
    left: 1em;
    top: 2em;
    z-index: 99;
    margin-left: 0;
 
}
.tooltip:hover img
{
    border: 0;
    margin: -10px 0 0 -55px;
    float: left;
    position: absolute;
}
.tooltip:hover em
{
    font-family: Verdana,Calibri, Tahoma, sans-serif;
    font-size: 1.2em;
    font-weight: bold;
    display: block;
    padding: 0.2em 0 0.6em 0;
}
 
.normal
{
    background: #d6d0fd;
    border: 1px solid #686868;
    word-wrap: break-word;
    width:200px;
    padding: 0.7em 1em;
}



For second problem you can use empty data template as solution
and use three templates header, item and empty

<HeaderTemplate>
                     <table cellpadding="0" cellspacing="0" border="0" width="100%">
                                                    <tr>
                                                        <td align="left" width="8%">
                                                            CompanyName
                                                        </td>
                                                        <td align="left">
                                                            SubIndustry
                                                        </td>
 
                                                    </tr>
                                                </table>
                                            </HeaderTemplate>

<EmptyDataTemplate>
 <table cellpadding="0" cellspacing="0" border="0" width="100%">
                                              <tr>
                                                  <td>
                                                      Sorry, 0 items found.
                                                  </td>
                                              </tr>
                                          </table>
</EmptyDataTemplate>

hope this will help..
  Permalink  
v2
Comments
pal5hah at 16-Nov-11 1:35am
   
thanks for your great idea
what is obj.CompanyName.Length and obj.CompanyName in that first code?????
sorry
dinidusoft123 at 16-Nov-11 1:59am
   
convert e in to your object inside the rowbound event
if (e.Row.RowType == DataControlRowType.DataRow)
{
YourObject objYourObject = (YourObject)e.Row.DataItem;
then take its properties of object. for this example i took your CompanyName which you bound to the label. i consider you have object that has company name property.
and the length is how many characters there inside that bound field. if it exist the our maximum limit. then put in to the tool tip
objYourObject.CompanyName
}
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

<asp:gridview id="gvList" runat="server" autogeneratecolumns="False" xmlns:asp="#unknown">
BackColor="White" BorderColor="#B2B2B2" BorderStyle="None" BorderWidth="1px"
CellPadding="2" DataSourceID="sqldsList"
AlternatingRowStyle-BackColor="#F8F8F8" ForeColor="Black"
GridLines="Horizontal" HeaderStyle-HorizontalAlign="Left"
Width="100%" AllowPaging="True" DataKeyNames="Id" >

<headerstyle horizontalalign="Left" />
<headerstyle backcolor="#B2B2B2" font-bold="false" forecolor="White" />
<selectedrowstyle backcolor="#CC3333" font-bold="True" forecolor="White" />>


This is the example of empty gridview.
  Permalink  
v2

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



Advertise | Privacy | Mobile
Web04 | 2.8.150731.1 | Last Updated 16 Nov 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100