具有附加功能的 GridView 排序
我有一个自动绑定到 SqlDataSource 的 GridView。我有一个函数可以遍历 GridView 并根据某些单元格的内容将其设置为红色。我还在所有列的 GridView 上启用了排序。当页面首次加载时,为适当的单元格着色的功能起作用。当我单击列标题进行排序时,它会进行排序,但应该着色的单元格不会着色。我尝试将对着色函数的调用放在 if(isPostBack) 条件下的 Page_Load 中,并尝试使用 GridView_Sorted 事件将对着色函数的调用放在那里。这些都不起作用。我还尝试在调用着色函数之前和之后在 Page_Load 和 GridView_Sorted 事件中添加 GridView1.DataBind() 。在所有情况下,排序都有效,但着色却无效! 如何同时进行排序和着色? 谢谢。
I have a GridView which is bound automaticaly to a SqlDataSource. I have a function which goes thru the GridView and colors red certain cells according to their content. I also enabled sorting on the GridView on all columns. When the page first loads the function coloring appropriate cells works. When I click the column header to sort, it sorts, but the cells that should be colored doen't get colored. I tried putting the call to the coloring function in the Page_Load in an if(isPostBack) condition and I tried using the GridView_Sorted event putting the call to the coloring function in there. None of that worked. I also tried adding GridView1.DataBind() in both the Page_Load and GridView_Sorted events before calling the coloring function and after. In all scenarios sorting worked but coloring did not!
How can I get both sorting and coloring working?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了接受答案,我在此处复制我的评论:
将您的着色逻辑放入 GridView 的 RowDataBound 事件。
To enable accepting the answer, i copy my comment here:
Put your coloring logic into GridView's RowDataBound event.
将着色放入 OnRowDataBound 事件中。
以这种方式为单元格着色,它将在数据绑定期间发生。
Put the coloring in the OnRowDataBound event.
Coloring the cells this way, it will happen during the databinding.