Interception of content in a DataGrid

Source: Internet
Author: User
When you use a DataGrid, you often encounter too much content in a cell that causes text to wrap, which makes a simple page look messy. The following methods can solve this problem.
When the contents of a cell exceed the specified length, the extra word is truncated, and the entire contents are displayed when the mouse hovers over a cell.
This method has a disadvantage: Each unit is a specified length.
A ItemDataBound event for a DataGrid.
The upper part sets the background color when the mouse hovers over
The bottom half works.
public void Datagrid1_itemdatabound (object sender, DataGridItemEventArgs e)
{
if (E.item.itemtype==listitemtype.item | | e.item.itemtype==listitemtype.alternatingitem)
{
Color color = this. DataGrid1.SelectedItemStyle.ForeColor;
String ForeColor = String. Format ("#{0:x2}{1:x2}{2:x2}", color. R, color. G, color. B);
color = this. DataGrid1.SelectedItemStyle.BackColor;
String BackColor = String. Format ("#{0:x2}{1:x2}{2:x2}", color. R, color. G, color. B);
If the color of the selected item is not set, the mouse effect is not set
if (ForeColor!= "#000000" | | | BackColor!= "#000000")
{
E.item.attributes.add ("onmouseover", String. Format ("Olditemforecolor=this.style.color;this.style.color= ' {0} '; olditembackcolor=this.style.backgroundcolor; This.style.backgroundcolor= ' {1} ' ", ForeColor, BackColor));
E.item.attributes.add ("onmouseout", "this.style.color=olditemforecolor;this.style.backgroundcolor= Olditembackcolor; ");
}
E.ITEM.CELLS[1]. Text = "<div style= ' text-overflow:ellipsis;" overflow:hidden;width:80px ' title= ' "+e.item.cells[1]. text+ "' ><nobr>" + e.item.cells[1]. Text + "</nobr></div>";
E.ITEM.CELLS[2]. Text = "<div style= ' text-overflow:ellipsis;" overflow:hidden;width:80px ' title= ' "+e.item.cells[2]. text+ "' ><nobr><a class=lan href= '" +this. request.applicationpath+@ "/uploadfile/" +system.io.path.getfilename (e.item.cells[7). Text) + "' >" + e.item.cells[2]. Text + "</a></nobr></div>";

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.