I have a dropdownlist bound to a cached string[], like so...
Cache["elems"] = items.elems; //typeOf(items.elems)=string[]
DropDownList1.DataSource = Cache["elems"];
DropDownList1.DataBind();
I want to limit the length of text displayed in DropDownList1 eg an element called "Manufacturing" would display "Manufact..." and have a value "Manufacturing"
How to do this?
Thanks to Mihai Caracostea I ended up with this...
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
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.