4

I have to show data from database with multiline textbox.
How can i set height auto in this multiline textbox?
My code is here,
<asp:TextBox ID="txtNaiyo" runat="server" TextMode="MultiLine" Rows="5" Width="100%" style="height:auto;" Value='<%# Eval("Naiyo") %>'/>

KMH
  • 61
  • 1
  • 1
  • 4

1 Answers1

3

I've made something quite easy. First I put the TextArea into a DIV. Second, I've called on Ready Function to this script

<div id="divTable">
  <textarea ID="txt" Rows="1" TextMode="MultiLine" />
</div>

$(document).ready(function () {
  var heightTextArea = $('#txt').height();
  var divTable = document.getElementById('divTable');
  $('#txt').attr('rows', parseInt(parseInt(divTable .style.height) / parseInt(altoFila)));
});

Simple. Is the Max Height of the div once is render, divided the height of one TextArea of one row.

Flexo
  • 87,323
  • 22
  • 191
  • 272
  • 2
    Welcome to Stack Overflow! Be careful when posting copy and paste boilerplate/verbatim answers to multiple questions, these tend to be flagged as "spammy" by the community. If you're doing this then it usually means the questions are duplicates so flag them as such instead: http://stackoverflow.com/questions/7477/autosizing-textarea-using-prototype/9572832#9572832 – Kev Mar 05 '12 at 23:42