"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Friday, May 21, 2010

Limiting the Data being displayed in the GridView and Display Tooltip


C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ViewState["OrigData"] = e.Row.Cells[0].Text;
                if (e.Row.Cells[0].Text.Length >= 30) //Just change the value of 30 based on your requirements
                {
                    e.Row.Cells[0].Text = e.Row.Cells[0].Text.Substring(0, 30) + "...";
                    e.Row.Cells[0].ToolTip = ViewState["OrigData"].ToString();
                }
             }
} 
VB.NET
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) 
    If e.Row.RowType = DataControlRowType.DataRow Then 
        ViewState("OrigData") = e.Row.Cells(0).Text 
        If e.Row.Cells(0).Text.Length >= 30 Then  'Just change the value of 30 based on your requirements 
            e.Row.Cells(0).Text = e.Row.Cells(0).Text.Substring(0, 30) + "..." 
            e.Row.Cells(0).ToolTip = ViewState("OrigData").ToString() 
        End If 
    End If 
End Sub 
 

Have a nice day... 'N happy Coding :)
 Illustrated C# 2008 (Windows.Net)Microsoft Visual C# 2008 Step by StepMicrosoft Visual C# 2010 Step by Step

No comments: