all groups > asp.net datagrid control > november 2007 >
You're in the

asp.net datagrid control

group:

wrap text in datagrid cell


wrap text in datagrid cell ireallyneedtoknow2007@yahoo.com
11/12/2007 5:17:21 AM
asp.net datagrid control:
here is a cleaner version of a question I posted yesterday. I have
tried many versions of the code below but cannot get the column to
wrap. I am using asp.net 2.0 visual studio 2005. ultimately I will
be adding template columns as well, but really need this column to
wrap. thanks for your help

<asp:datagrid id="myDataGrid" style="Z-INDEX: 100; LEFT: 20px;
POSITION: absolute; TOP: 260px" runat=server
AllowSorting="True" Font-Size="X-Small" Font-Names="Verdana"
ForeColor="Black"
GridLines="None" CellPadding="2" BackColor="LightGoldenrodYellow"
BorderWidth="1px"
BorderColor="Tan" Width="100px" Height="304px"
OnPreRender="myDataGrid_PreRender" AutoGenerateColumns="False"
BorderStyle="Solid" CellSpacing="2">

<Columns>
<asp:BoundColumn DataField="contact_email" ReadOnly="True"
HeaderText="Emailx">
<ItemStyle Wrap="True" ></ItemStyle>
<HeaderStyle Width="5px" Wrap=true/>
</asp:BoundColumn>
</Columns>

</asp:datagrid>



public void myDataGrid_PreRender(object sender, System.EventArgs e)
{
myDataGrid.Columns[0].ItemStyle.Width = 30;
myDataGrid.Columns[0].ItemStyle.Wrap = true;
}
RE: wrap text in datagrid cell Peter Bromberg [C# MVP]
11/12/2007 7:48:00 AM
Take a look at "word-break:break-word" and similar CSS style behaviors.
-- Peter
http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com



[quoted text, click to view]
Re: wrap text in datagrid cell ireallyneedtoknow2007@yahoo.com
11/12/2007 3:00:50 PM
thanks, no doubt I did something wrong but I could not get <style> to
work. however replacing a comma with a comma<br> in my sql did give
me what I needed.

<style>
.fixed_cell
{
word-wrap:break-word;
width:25px;
}
</style>

<asp:BoundColumn DataField="contact_email" ReadOnly="True"
HeaderText="Email" ItemStyle-CssClass="fixed_cell" >


select replace(contact_email,',',',<br>') as contact_email from mytable
AddThis Social Bookmark Button