Monday, September 8, 2008

Word Break for Gridview/DataGrid

Sometime we are facing problems with gridview in inserting word breaks to format the grid.ie if we are inserting a coloumn that is having more length so the grid layout is changed.

"wbr" Tag is used for that.That should be placed in angle bracket("<>").I'm representing it as wbr in the code given below as it is an html tag.

public static string WordBreak(String inString, int length)
{
StringBuilder stb = new StringBuilder();
String ret = "";
int pos;
if (length == 0)
length = 10;
while ((true))
{
if (inString.Length <= length)
{
ret += inString;
break;
}
pos = inString.IndexOf(" ");
if (pos != -1)
{
if (pos > length - 1)
{
pos = length;
ret += inString.Substring(0, pos + 1) + "wbr";
}
else
{
ret += inString.Substring(0, pos + 1);
}
inString = inString.Substring(pos + 1);
}
else
{
ret += inString.Substring(0, length) + "wbr";
inString = inString.Substring(length);
}
}
if (ret.Length > 50)
{
string temp = ret.Substring(0, 50);
stb.Append(temp);
stb.Append("....");
ret = stb.ToString();
}
return ret;
}


Regards
www.renjucool.com

2 comments:

Anonymous said...

Visit http://www.foosms.com for sending free sms.. :)

Anonymous said...

Complete tech website visit

http://24x7answers.com

Also visit

http://travel2karnataka.com