Dynamically Changing DIV height

STEVESKI07

Member
Joined
Sep 12, 2007
Messages
17
Programming Experience
1-3
Hey everyone,

I have read a few posts similar to my question but can't get any of them to work. Here's my situation...

I have a datagrid with a scroll bar and this is all placed inside a DIV. I want to dynamically change the size of the grid by passing a value from the code behind (# of rows in the grid) to the Javascript function to set the size of the DIV.

I have even resorted to sloppy code just to try to get it working and still can't.

This is the code I put in my VB file:
VB.NET:
radSetHeight.Attributes.Add("OnClick", "setDivHeight(i);")
radSetHeight.Checked = True

This is the code I have in my aspx file:
HTML:
<script type="text/javascript">
			var divHeight;
			function setDivHeight(size)
			{
				if (size=1)
				{
				divHeight = 85;
				}
				else if (size>17)
				{
				divHeight = 750;
				}
				else
				{
				divHeight = 85*size;
				}
				document.getElementById("divByStateDataGrid").style.height= divHeight;
			} 	
		</script>

does anybody have any suggestions?
 
Last edited by a moderator:
I figured it out and it was MUCH easier then I thought. Just in case other people are trying to do the same thing...here's what I did.

Code Behind:

Protected divDataGrid As New HtmlGenericControl
divDataGrid = CType(Me.Page.FindControl("divDataGrid"), HtmlGenericControl)

divDataGrid.Style.Add("height", "300 px")


HTML code:
just had to add runat="server" to the <div id="divDataGrid"> tag
 
Back
Top