Dynamic Sizing of ASP.Net Textbox

This tip uses the Northwind Database Employee table columns. First – create a connection and a DataReader…
Then, add lines similar to the following, creating variable names for returned items to match your particular sql statement:

While objDR.Read()	strFirst=Trim(objDR("Firstname"))	strLast=Trim(objDR("LastName"))	strTitle=Trim(objDR("Title"))End While

Here’s the function that does the actual work:

Function doLen(item as string)	Dim intWdth as int32	intWdth=item.Length * 7	doLen = Unit.point(intWdth)End Function

(to get better spacing so the ‘*7′ part of the function works better, I optionally added a CSSClass which forces the textbox font to Courier)

Then, inside the ASP.Net TextBox server control, for each one, include the following:
Width=”<%# doLen(varName)%>”

Thanks to DataGridGirl for collaboration on this one.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>