簡體   English   中英

綁定到緩存的字符串數組時如何操作DropDownList DataTextField

[英]How to manipulate a DropDownList DataTextField when bound to a cached string array

我有一個綁定到緩存的字符串[]的下拉列表,就像這樣...

Cache["elems"] = items.elems;   //typeOf(items.elems)=string[]
DropDownList1.DataSource = Cache["elems"];
DropDownList1.DataBind();

我想限制DropDownList1中顯示的文本的長度,例如,名為“ Manufacturing”的元素將顯示“ Manufact ...”並具有值“ Manufacturing”

這個怎么做?

多虧了Mihai Caracostea,我才結束了這個...

    protected void DropDownList1_DataBound(object sender, EventArgs e)
    {
        foreach (ListItem myItem in DropDownList1.Items)
        {
            try
            {
                if (myItem.Text.Length > 8)
                    myItem.Text = myItem.Text.Substring(0, 11) + "...";
            }
            catch (ArgumentOutOfRangeException ex) 
            { 
                //do nothing
            }
        }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM