如何控制DataGrid里的内容换行与不换行?
来源:互联网 发布:字符串压缩算法php 编辑:程序博客网 时间:2024/05/16 11:14
<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>
<html>
<script runat="server">
int start_index;
ICollection CreateDataSource()
{
DataTable dt = new DataTable();
DataRow dr;
dt.Columns.Add(new DataColumn("IntegerValue", typeof(Int32)));
dt.Columns.Add(new DataColumn("StringValue", typeof(string)));
dt.Columns.Add(new DataColumn("CurrencyValue", typeof(double)));
for (int i = start_index; i < start_index + ItemsGrid.PageSize; i++)
{
dr = dt.NewRow();
dr[0] = i;
dr[1] = @"我是中文文字,I am English words,我不想换行,
I don't wanna have new lines,欢迎访问
<a href='http://dotnet.aspx.cc/'>http://dotnet.aspx.cc/</a>,
有好料啊:)";
dr[2] = 1.23 * (i+1);
dt.Rows.Add(dr);
}
DataView dv = new DataView(dt);
return dv;
}
void Page_Load(Object sender, EventArgs e)
{
//对于没有数字的内容,下面这行完全满足要求,但加了数字就不行,必须调用OnItemDataBound
ItemsGrid.Attributes.Add("style","word-break:keep-all;word-wrap:normal");
//下面这行是自动换行
//ItemsGrid.Attributes.Add("style","word-break:break-all;word-wrap:break-word");
if (!IsPostBack)
{
BindGrid();
}
}
void BindGrid()
{
ItemsGrid.DataSource=CreateDataSource();
ItemsGrid.DataBind();
}
void Item_DataBound(Object sender, DataGridItemEventArgs e)
{
if( e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
e.Item.Cells[1].Text = "<nobr>" + e.Item.Cells[1].Text + "</nobr>";
}
</script>
<body>
<form runat="server">
<asp:DataGrid id="ItemsGrid" runat="server" BorderColor="black"
OnItemDataBound="Item_DataBound" AutoGenerateColumns="false">
<AlternatingItemStyle BackColor="#DEDEDE"></AlternatingItemStyle>
<HeaderStyle BackColor="#EEEEFF" HorizontalAlign="Center"></HeaderStyle>
<Columns>
<asp:BoundColumn HeaderText="序号" DataField="IntegerValue"/>
<asp:BoundColumn HeaderText="文字" DataField="StringValue"/>
<asp:BoundColumn HeaderText="价格" DataField="CurrencyValue" DataFormatString="{0:c}">
<ItemStyle HorizontalAlign="right"></ItemStyle>
</asp:BoundColumn>
</Columns>
</asp:DataGrid>
</form>
</body>
</html>
- 如何控制DataGrid里的内容换行与不换行?
- 如何控制DataGrid里的内容换行与不换行?
- 如何控制DataGrid里的内容换行与不换行?
- 如何控制DataGrid里的内容换行与不换行?
- 如何控制DataGrid里的内容换行与不换行?
- 如何控制DataGrid里的内容换行与不换行?
- 如何控制DataGrid里的内容换行与不换行?
- 如何控制DataGrid里的内容换行与不换行?
- 如何控制DataGrid里的内容换行与不换行?
- 如何控制DataGrid里的内容换行与不换行?
- 如何控制DataGrid里的内容换行与不换行
- 如何控制DataGrid里的内容换行与不换行?(转)
- Datagrid的不换行
- 控制td里面的内容不换行
- 中英文在html中换行与不换行的控制
- DataGrid控件中内容不换行的处理
- CSS控制换行与不换行
- 表单列里面的内容不换行控制。(nowrap)
- Sweet Titles - 气泡窗口 - 鼠标提示信息美化
- 获取自动编号列(标识列)的编号
- Linux下守护进程的创建
- [转]采用dwr+ajax和struts开发文件上传进度条
- Linux那些事儿之我是U盘(49)跟着感觉走(一)
- 如何控制DataGrid里的内容换行与不换行?
- 什么是服务?
- 实际项目中配置SSL实例之二 weblogic8上配置ssl(共4篇)
- Miscellaneous
- Best SMS to Type pku 2895
- 学习.Net的经典网站
- 超强兔斯基。。。一学期内表情的变化--兔斯基版 转校内
- 比尔·盖茨在哈佛大学毕业典礼上的演讲
- 让你的电脑自动关机