自定义gridview override无效

hackerxxw 2009-02-24 10:07:53
我试了试继承一个Gridveiw的自定义控件 ,重写gridview的OnRowDataBound和OnRowCreated
但是无效?
代码如下:

public class MyGridView:GridView
{

public MyGridView()
{
//构造函数
}

protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
base.Render(writer);
}

protected override void OnRowDataBound(GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#99cc00';");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor;");
}
base.OnRowDataBound(e);
}

protected override void OnRowCreated(GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
TableCellCollection tcHeader = e.Row.Cells;
tcHeader.Clear();
}
base.OnRowCreated(e);
}

}
...全文
128 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
hackerxxw 2009-02-25
  • 打赏
  • 举报
回复
差不多吧 就是比如:需要统计gridview某列,可通过查看列的属性值确定是否统计
du9232 2009-02-25
  • 打赏
  • 举报
回复
不是很明白,呵呵
不过DataGridView里有DataGridViewColumn对象集合,每个Column都有自己的类型和属性,不知道你说的是不是这个
hackerxxw 2009-02-25
  • 打赏
  • 举报
回复
哦 明白了

最后请教一个问题
如何为Gridview的列定义属性啊?
du9232 2009-02-25
  • 打赏
  • 举报
回复
如果是自定义的属性可以放在Tag属性里保存
hackerxxw 2009-02-24
  • 打赏
  • 举报
回复
还是无效 这个base.OnRowDataBound(e)的位置放在哪里都没有关系吧
du9232 2009-02-24
  • 打赏
  • 举报
回复
base.OnRowDataBound(e);
写在前面试试
stonehy520 2009-02-24
  • 打赏
  • 举报
回复
学习,关注
du9232 2009-02-24
  • 打赏
  • 举报
回复
有些属性上没有加[Browsable]属性(attribute)的的属性就不能在属性窗口上显示。
hackerxxw 2009-02-24
  • 打赏
  • 举报
回复
糊涂了 我把那个控件项目设为Release 没有运行到那里 改为Debug就可以了

请问一下gridview的属性 定义 为什么只有编程的时候才能使用啊
不能想其他的Gridview属性一样 可视化啊?
du9232 2009-02-24
  • 打赏
  • 举报
回复
设个断点调试一下。

如果执行到了也没有效果说明不能这样写

8,833

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 组件/控件开发
社区管理员
  • 组件/控件开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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