DropDownList
来源:互联网 发布:js函数创建表格 编辑:程序博客网 时间:2024/05/17 11:37
ListBoxScenes.DataSource = olympicTickets.OlympicScenesGetInfo();ListBoxScenes.DataTextField = "OSceneInfo";ListBoxScenes.DataValueField = "OSceneID";ListBoxScenes.DataBind();ListItem list = new ListItem();list.Text = "请选择场次元素来形成场次";list.Value = "-1";ListBoxScenes.Items.Insert(0, list);ListBoxScenes.SelectedIndex = 0; <script type="text/javascript"> window.onload=function() { document.all("DivScenes").style.height=document.body.scrollHeight; document.all("ListBoxScenes").style.height=document.body.scrollHeight-16; document.all("DivTime").style.height=document.body.scrollHeight-60; document.all("ListBoxTime").style.height=document.body.scrollHeight-76; document.all("DivFields").style.height=document.body.scrollHeight-60; document.all("ListBoxFields").style.height=document.body.scrollHeight-76; document.all("DivItem").style.height=document.body.scrollHeight-60; document.all("ListBoxItem").style.height=document.body.scrollHeight-76; } </script><div id='DivItem' runat="server" style="z-index: 1; overflow: auto;"> <asp:ListBox ID="ListBoxItem" runat="server" Height="500"></asp:ListBox></div>SetListBoxWidthHight(ListBoxItem, DivItem, 200, 500, 10, 0);private int intCompare(int aint, int bint){ if (aint > bint) { return aint; } else { return bint; }}private void SetListBoxWidthHight(ListBox lb,HtmlGenericControl hgc, int setWidth, int setHeight,int offsetWidth,int offsetHeight){ int realheight = (int)(((float)100 / 6) * lb.Items.Count) + offsetHeight; int realWidth = 0; for (int i = 0; i < lb.Items.Count; i++) { realWidth = intCompare(realWidth, assistantBll.GetStrLen(lb.Items[i].Text)); } realWidth = (int)(((float)68 / 10) * realWidth) + offsetWidth; if (realWidth < 50) { lb.Width = 50; hgc.Style["width"] = "50px"; } else { lb.Width = realWidth; if (realWidth > setWidth)//宽度取小 { hgc.Style["width"] = setWidth.ToString() + "px"; } else { hgc.Style["width"] = realWidth.ToString() + "px"; } } if (realheight < setHeight) { lb.Height = setHeight; } else { lb.Height = realheight; } hgc.Style["height"] = (setHeight).ToString() + "px";}//取字符串实际长度 public int GetStrLen(string str) { System.Text.ASCIIEncoding n = new System.Text.ASCIIEncoding(); byte[] b = n.GetBytes(str); int l = 0; // l 为字符串之实际长度 for (int i = 0; i <= b.Length - 1; i++) { if (b[i] == 63) //判断是否为汉字或全脚符号 { l++; } l++; } return l; }