怎么设置gridview可拖列宽

www5net 2014-03-08 03:36:13
怎么设置gridview可拖列宽 VS2010 网上设的几个试了下没用 是我没代码没放好还是怎么的
js:
<script language="javascript" type="text/javascript">
//设置Datagrid列宽可以被拖动的函数
function SyDG_moveOnTd(td) {
if (event.offsetX > td.offsetWidth - 10)
td.style.cursor = 'w-resize';
else
td.style.cursor = 'default';
if (td.mouseDown != null && td.mouseDown == true) {
if (td.oldWidth + (event.x - td.oldX) > 0)
td.width = td.oldWidth + (event.x - td.oldX);
td.style.width = td.width;
td.style.cursor = 'w-resize';
table = td;
while (table.tagName != 'TABLE') table = table.parentElement;
table.width = td.tableWidth + (td.offsetWidth - td.oldWidth); table.style.width = table.width;
}
}
function SyDG_downOnTd(td) {
if (event.offsetX > td.offsetWidth - 10) {
td.mouseDown = true;
td.oldX = event.x;
td.oldWidth = td.offsetWidth;
table = td; while (table.tagName != 'TABLE') table = table.parentElement;
td.tableWidth = table.offsetWidth;
}
}
</script>
cs:
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
if (true)//如果允许改变列宽
{
for (int i = 0; i < e.Row.Cells.Count; i++)
{
e.Row.Cells[i].Attributes.Add("onmousemove", "SyDG_moveOnTd(this)");
e.Row.Cells[i].Attributes.Add("onmousedown", "SyDG_downOnTd(this)");
e.Row.Cells[i].Attributes.Add("onmouseup", "this.mouseDown=false");
e.Row.Cells[i].Attributes.Add("onmouseout", "this.mouseDown=false");
}
}
}
}
...全文
194 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
淡淡的活着 2014-03-24
  • 打赏
  • 举报
回复
用Grid吧··
H_Gragon 2014-03-24
  • 打赏
  • 举报
回复
Gridview不支持拖拽!
thewitcher~ 2014-03-24
  • 打赏
  • 举报
回复
GridView不支持拖列宽的,可以用jqGrid。
MJIT 2014-03-24
  • 打赏
  • 举报
回复
真不能拖嗎,學習了
www5net 2014-03-24
  • 打赏
  • 举报
回复
额, 。。能写个javascript 脚本实现吗

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧