这是非常基本的东西,但我无法从网格视图中的单元格中提取文本。
<asp:TemplateField HeaderText="Rolle" SortExpression="role">
<ItemTemplate>
<asp:Label ID="roleLabel" runat="server" Text='<%# Eval("role") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList style="width: 200px;" ID="roleDropdown" runat="server" DataSourceID="SqlDataSourceDropDownlist" DataTextField="role" DataValueField="roleID"></asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
Protected Sub GridView1_rowediting(sender As Object, e As GridViewEditEventArgs) Handles GridView1.RowEditing
Dim tb As Label
tb = CType(GridView1.SelectedRow.Cells(1).FindControl("roleLabel"), Label)
Dim userRoleString As String = tb.Text
End Sub
我收到了这个错误:
Object reference not set to an instance of an object.
如何从 GridView 中的单元格中提取文本?