gridview中的数据显示问题 [英] data display problem in gridview

查看:62
本文介绍了gridview中的数据显示问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家早上好
在gridview显示中,我的某些数据值太长,因此在显示中它们显得过分愚弄.
如果我设置了固定宽度,那么如果将来要插入的任何数据会更多,那么该宽度就会出现问题.
有什么解决办法吗?
另一个问题是,如果我的数据库中没有数据意味着0条记录,那么将不会显示gridview.但是我希望即使没有记录也要显示我的标头

-------------------------------------------------- ----------------------------------

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>
                            
<columns>
                               
 <asp:TemplateField HeaderText="companyid" Visible="false">
<itemtemplate>
<asp:Label ID="lblBindId" runat="server" Text='<%#Eval("ID") %>' />
                                    </itemtemplate>
                                    <HeaderStyle CssClass="table-header-repeat line-left minwidth-1" ForeColor="White">
                                    </HeaderStyle>
                                
                                <asp:TemplateField HeaderText="CompanyName">
                                    <itemtemplate>
                                        <asp:Label ID="lblBindName" runat="server" Text='<%#Eval("CompanyName") %>' />
                                    </itemtemplate>
                                    <HeaderStyle CssClass="table-header-repeat line-left minwidth-1" ForeColor="White">
                                    </HeaderStyle>
                                
                                <asp:TemplateField HeaderText="SubIndustry">
                                    <itemtemplate>
                                        <asp:Label ID="lblcmpnynm" runat="server" Text='<%#Eval("SubIndustry") %>' />
                                    </itemtemplate>
                                    <HeaderStyle CssClass="table-header-repeat line-left minwidth-1" ForeColor="White">
                                    </HeaderStyle>
                                
                                
                                
                            </columns>
                            
                            <HeaderStyle Height="50px"></HeaderStyle>
                            <alternatingrowstyle cssclass="alternate-row"></alternatingrowstyle>
                            <pagerstyle height="15px" font-size="Medium" />
                        
                            
                    </div>

推荐答案

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

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();
       }


对于第一个问题,您可以使用工具提示作为解决方案,并使用固定宽度.因此其他字词会显示在工具提示中.下面我展示了编写工具提示解决方案的方法,希望您可以对其进行编辑并根据您的解决方案对其进行自定义.

在OnRowDataBound事件中,设置适合列和发送到工具提示的其他字符的最大长度.
在onrowbound事件中使用此代码
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..


< 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 ="Horizo​​ntal" HeaderStyle-Horizo​​ntalAlign ="Left"
宽度="100%" AllowPaging ="True" DataKeyNames ="Id">

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


这是一个空的gridview的示例.
<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.


这篇关于gridview中的数据显示问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆