Tuesday, July 7, 2009

Limiting Data from GridView

while Desinging GridView we want some special effets like (coloring , bold, Setting width , height )
and so many , you can do this by handling event like RowCreated and implementing event handler for it OnRowCreated.


<asp:GridView ID="ctlGridView" runat="server" OnRowCreated="OnRowCreated" />


And in your code behind you can add


protected void OnRowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string Comments = (String)DataBinder.Eval(e.Row.DataItem, "Comment");
if (Comments != null)
{
if (Comments.Length > 30)
{
Comments = Comments.Substring(0, 40) + "...";
e.Row.ForeColor = System.Drawing.Color.red;

}
}
}
}


in that on "Comment" filed , i just simply minimize the string uptp 40 character and make it as a "RED" color.
like that you can add more feature as u want.

No comments:

Post a Comment