Hi Brian,
As for the truncating string values in DataGrid Cell(Table cell), I think
generally we have two means:
1. Truncating the string's length at serverside when we retrieve it from db
or output into the page via code. Just as the other members have suggested.
But this will make the output string's length be a fixed size.
#Creating a Custom DataGridColumn Class, Part 2
http://aspnet.4guysfromrolla.com/art...00202-1.2.aspx
2. Using css style on the output <table> and the text content in table
cell. There is one css attribute named
"OVERFLOW", it can be applied on <div> or <p> ... and when we set the
"OVERFLOW:Hidden", it will truncat the exceeded content according to the
container element's width.
#overflow Attribute | overflow Property
http://msdn.microsoft.com/library/de...thor/dhtml/ref
erence/properties/overflow.asp
For example:
<p style="OVERFLOW:hidden;WIDTH:100">
<% Response.Write(new String('d',1000)); %>
</p>
Also, since in our problem, we need to set the datagrid column's width
unfixed, so we also need to make the with of the <p> as a relative size.
After some testing, it seems that we also have to assign the "table-layout
: fixed" css attribute to the DataGrid(<table>). Here is some demo code on
applying the styles on datagrid:
<asp:DataGrid id="dgStyle" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="Column1"
HeaderText="Column1"></asp:BoundColumn>
<asp:BoundColumn DataField="Column2"
HeaderText="Column2"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Column3">
<ItemTemplate>
<p style="OVERFLOW:hidden;WIDTH:90%">
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.Column3") %>'>
</p>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
=======================
In our code-behind , we can use the following code (in Page_load) to apply
the "table-layout" style on datagrid:
private void Page_Load(object sender, System.EventArgs e)
{
....................
dgStyle.Style["TABLE-LAYOUT"] = "fixed";
}
Hope these help. Thanks.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)