How to dynamically set the maxlength property of bound textbox from database field length
<p>I have an asp.net 4.0 c# web application. I am using listview and formview controls with templates on my forms. I am trying to control the maxlength property of my bound textboxes without hard coding the field sizes into my aspx pages. I would like to when I first load the application fill some kind of local object or array with the column lengths of my fields and then use those values to dynamically set the maxLength field of textboxes.
There are so many methods out there to try and I am not sure what is the most efficient.
My sql to get the schema info is </p>

<pre><code>SELECT     TOP (100) PERCENT sys.sysobjects.name AS TableName, sys.syscolumns.name AS ColumnName, sys.systypes.name AS DataType, 
                      sys.syscolumns.length
FROM         sys.sysobjects INNER JOIN
                      sys.syscolumns ON sys.sysobjects.id = sys.syscolumns.id INNER JOIN
                      sys.systypes ON sys.syscolumns.xtype = sys.systypes.xtype WHERE     (sys.sysobjects.xtype = 'U') AND (sys.systypes.name &lt;&gt; 'sysname')
ORDER BY TableName, sys.syscolumns.colid
</code></pre>

<p>how can i store this locally so I don't have to keep querying the server and I can I set this dynamically using c#</p>

<p>I am a semi newbie so as much detail as can be provided would be appreciated.</p>
