为什么只OnRowDataBound射击对我的头,而不是我的数据行? [英] Why is OnRowDataBound only firing for my headers and not my data rows?

查看:447
本文介绍了为什么只OnRowDataBound射击对我的头,而不是我的数据行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个GridView看起来是这样的:

I have a GridView that looks something like this:

<asp:GridView ID="MyGridView" 
              runat="server" 
              AutoGenerateColumns="False" 
              OnRowDataBound="MyGridView_RowDataBound" >
   <asp:HyperLinkField . . . . . bla bla/>
   <asp:BoundField . . . . . . . bla bla/>
</asp:GridView>

我的事件处理程序(MyGridView_RowDataBound)有效看起来是这样的:

My event handler (MyGridView_RowDataBound) effectively looks like this:

protected void MyGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
   if (e.Row.RowType != DataControlRowType.DataRow)
     return;

   // do stuff here
}

由于某些原因,我的code永远不会到达'//在这里做的东西行。它不会让过去的数据行检查,因为 OnRowDataBound 只烧我的标题行。

我已经验证了数据行获得通过使用 MyGridView_RowCreated 处理创建。这也很明显,结合正在发生,因为当我运行的网站,我可以看到从我的数据库中的行显示出来。最重要的是,我已经验证了 MyGridView.DataBind()语句正在运行。

I have verified that data rows get created by using a MyGridView_RowCreated handler. It is also obvious that the binding is taking place because when I run the website I can see the rows from my database showing up. On top of that, I have verified that the MyGridView.DataBind() statement is running.

有什么我忽略了导致我的事件处理程序,不会触发数据行?

What have I overlooked that is causing my event handler to not fire for data rows?

编辑:经进一步检查,它看起来像 GridView.DataBound 事件不会触发可言,所以我不能使用数据绑定,然后通过行循环。

Upon further inspection, it looks like the GridView.DataBound event isn't firing at all, so I can't use DataBound and then loop through the rows.

推荐答案

有是code结合过程中被被抓深处发生的异常。因为绑定并没有完全完成, OnRowDataBound 从来没有要求的任何数据行。这似乎是在绑定成功完成的原因是因为,我预计将有结果中的所有单元让他们(因为是部分完成了绑定),并预期有问题的电池没有结果。解决这个异常后, OnRowDataBound 解雇预期每个数据行。

There was an exception occurring deep within the code that was being caught during the binding process. Because the binding did not finish completely, OnRowDataBound was never called for any of the data rows. The reason it seemed like the binding completed successfully was because all the cells that I expected to have results had them (because the binding was partially complete), and the problematic cells didn't have results as expected. After fixing this exception, OnRowDataBound fired as expected for each data row.

这篇关于为什么只OnRowDataBound射击对我的头,而不是我的数据行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆