比如说绑定gridview某个字段过长,用。。。显示,然后鼠标放上去显示全部内容。
HTML代码:这时gridview用lable绑定。 ToolTip 是显示鼠标移上去的内容。
<asp:GridView ID="grv" runat="server" DataKeyNames="zcbm" CssClass="dataTableStyle" ForeColor="#333333" CellPadding="3" CellSpacing="1" GridLines="None" AutoGenerateColumns="False"> <Columns> <asp:BoundField DataField="zcbm" HeaderText="资产编码"> <HeaderStyle Wrap="False" /> <ItemStyle Wrap="False" /> </asp:BoundField> <asp:TemplateField HeaderText="资产名称"> <ItemTemplate> <asp:Label ID="Label5" runat="server" ToolTip='<%# Bind("ZCMC") %>' Text='<%# ycwz(Eval("ZCMC")) %>'></asp:Label> </ItemTemplate> <HeaderStyle Wrap="False" /> <ItemStyle Wrap="False" /> </asp:TemplateField> </Columns> <PagerSettings Visible="False"></PagerSettings> <RowStyle BackColor="White" HorizontalAlign="Left" /> <FooterStyle BackColor="#7799CC" Font-Bold="True" ForeColor="White" /> <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /> <HeaderStyle Font-Size="Large" BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <AlternatingRowStyle BackColor="White" /> </asp:GridView>
后台:
public partial class wsw_测试_文本过大点点显示 : System.Web.UI.Page { CX.DBGetResult dbgr = new CX.DBGetResult(CX.AppInfo.DBMS, CX.AppInfo.ConStr); protected void Page_Load(object sender, EventArgs e) { string sql="select * from zc_pdsj "; DataTable dt1 = this.dbgr.GetDataTable(sql); grv.DataSource = dt1; grv.DataBind(); } public string ycwz(object tex) { if (tex.ToString().Length > 4) { return tex.ToString().Substring(0, 3) + "..."; } else { return tex.ToString(); } } }