ScrollGridView 标题不变化 内容变化

本文介绍了一种实现 ASP.NET GridView 控件中单元格文本自动换行的方法,并通过 JavaScript 和 C# 后端代码结合使用,确保了当单元格内容过长时能够正常展示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<script type="text/javascript">
function fixHead() {
var grid = document.getElementById("<%=GridView1.ClientID%>");
var grid2 = grid.cloneNode(true)
for (i = grid2.rows.length - 1; i > 0; i--)
grid2.deleteRow(i)
grid.deleteRow(0)
divHead.appendChild(grid2)
}
window.onload = fixHead
</script>

 

<div id="divHead" style="width: 420px">
</div>
<div style="overflow: scroll; width: 420px; height: 150px">

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="BulletinID"
EmptyDataText="没有可显示的数据记录。" OnRowDataBound="GridView1_RowDataBound" CellPadding="4"
ForeColor="#333333" GridLines="None">

  </asp:GridView>

style="overflow: scroll; width: 420px; height: 150px">

 </div>

 

 

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow) //如果是数据行
{
string content = e.Row.Cells[2].Text;
//已设置公告内容列的宽度是20
//给公告内容列添加word-break属性
e.Row.Cells[2].Style.Add("word-break", "break-all");
}
}

转载于:https://www.cnblogs.com/Yellowshorts/archive/2013/01/19/2867819.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值