J
Jack Tonk
Hello. I have a simple datagrid with a column containing the last names of
authors. When a condition is met, I'd like the column to contain a textbox
which allows the user to change the last name. Otherwise, the cell will
contain a label which displays the last name but won't allow any editing.
The code is below. I keep getting Object reference not set to an instance
of an object errors. It seems like this should work. Any ideas?
Thanks in advance.
The .aspx snippet:
<asp
ataGrid ID="dgLastNames" Runat="server" AutoGenerateColumns="false"
DataKeyField=UnProcessedID>
<Columns>
<asp:TemplateColumn HeaderText="Authors">
<ItemTemplate>
<asp:Label ID="lblLastName" Runat="server">last name</asp:Label>
<asp:TextBox id="tbLastName" runat="server">last
name</asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp
ataGrid>
The .aspx.vb snippet:
Private Sub dgLastNames_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
dgLastNames.ItemDataBound
Dim lblLastName As Label
lblLastName= CType(e.Item.FindControl("lblLastName"), Label)
Dim tbLastName As TextBox
tbLastName = CType(e.Item.FindControl("tbLastName"), TextBox)
if somecondition = true then
lblProductType.Visible = False
tbLastName.Visible = true
else
lblProductType.Visible = true
tbLastName.Visible = false
end if
End Sub
authors. When a condition is met, I'd like the column to contain a textbox
which allows the user to change the last name. Otherwise, the cell will
contain a label which displays the last name but won't allow any editing.
The code is below. I keep getting Object reference not set to an instance
of an object errors. It seems like this should work. Any ideas?
Thanks in advance.
The .aspx snippet:
<asp
DataKeyField=UnProcessedID>
<Columns>
<asp:TemplateColumn HeaderText="Authors">
<ItemTemplate>
<asp:Label ID="lblLastName" Runat="server">last name</asp:Label>
<asp:TextBox id="tbLastName" runat="server">last
name</asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp
The .aspx.vb snippet:
Private Sub dgLastNames_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
dgLastNames.ItemDataBound
Dim lblLastName As Label
lblLastName= CType(e.Item.FindControl("lblLastName"), Label)
Dim tbLastName As TextBox
tbLastName = CType(e.Item.FindControl("tbLastName"), TextBox)
if somecondition = true then
lblProductType.Visible = False
tbLastName.Visible = true
else
lblProductType.Visible = true
tbLastName.Visible = false
end if
End Sub