如何在绑定到缓存的字符串数组时操作 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
}
}
}
我有一个绑定到缓存字符串的下拉列表[],就像这样...
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
}
}
}