Saturday, 19 January 2013 15:54

how to make textbox height according to content

Written by 
Rate this item
(0 votes)

if you want to resize your asp.net textbox height according
to content then these codes will help you perfectly.

in the following codes first the text from db is splitted by
\n to get number of lines.then if the characters per
line is over 48 then another line added.at last textbox
Rows is set according to lines -

string Comment=obj.Text;//first gets the content from database
int y = 0; int lines; int temp; int lines2;
string[] linesarray = Regex.Split(Comment, "\n");
lines = Convert.ToInt32(linesarray.Length);
lines2 = lines;
for (int app = 0; app < lines2; app++)
{
temp = linesarray[app].Length / 48;
if (temp > 0) { lines = lines + temp; }
}
if (lines > 7)
{
if (lines > 21) { setrows.Rows = 21; } else { setrows.Rows = lines; }
}
else
{ setrows.Rows = 7; } y++;

Read 1030 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.
Login to post comments