我有一个简单的gridview,其中一行包含一个标签.我试图在RowDataBound事件中访问该标签,但由于某种原因,我不断得到"对象引用未设置为对象的实例".我正在使用FindControl的行上的错误.
我尝试过使用"gvQReport.FindControl","e.Row.FindControl"和"Me.FindControl",但没有任何效果.
我没有这样做吗?
谢谢!
Protected Sub gvQReport_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
Dim lblTest As Label = CType(gvQReport.FindControl("lblTest"), Label)
lblTest.Text = "test Label"
End Sub
<asp:GridView ID="gvQReport" OnRowDataBound="gvQReport_RowDataBound" runat="server">
<Columns>
<asp:TemplateField HeaderText="Test">
<ItemTemplate>
<asp:Label ID="lblTest" runat="server" Text=""></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Run Code Online (Sandbox Code Playgroud)
该行的性质GridViewRowEventArgs是当前行,寻找你控制了,而不是整体GridView.
Protected Sub gvQReport_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
Dim lblTest As Label = CType(e.Row.FindControl("lblTest"), Label)
lblTest.Text = "test Label"
End If
End Sub
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2544 次 |
| 最近记录: |