Friday, 25 October 2013

Gridview column bind with substring and ... if exceed column width limit and showing tooltip with entirecolumn text

 <asp:Label ID="lblProperty" runat="server" Text='<%# Eval("PropertyName").ToString().Length <= 15 ?                Eval("PropertyName") : Eval("PropertyName").ToString().Substring(0,15)+"..." %>'
             ToolTip='<%# Eval("PropertyName") %>' Visible="true"></asp:Label>



we also can do this substring column by using row data bound event below code explain how we can do this

  protected void grvVendorProperties_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            if (e.Row.RowType == DataControlRowType.DataRow)
            {

     Label lblName = (Label)e.Row.FindControl("lblProperty");
                string strName = lblName.Text;
                if (strName.Length > 7)
                {
                    lblName.Text = strName.Substring(0, 7) + "..";
                    lblName.ToolTip = strName;
                }
}
}

No comments:

Post a Comment