DropDownList

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;
    }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值