![]() |
datagrid problem
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:DataGrid 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:DataGrid> 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 |
Re: datagrid problem
Hi Jack,
Try it this way... Private Sub dgLastNames_ItemDataBound(sender As Object, e As DataGridItemEventArgs) Dim lblLastName As Label lblLastName= CType(e.Item.cells(0).FindControl("lblLastName"), Label) Dim tbLastName As TextBox tbLastName = CType(e.Item.cells(0).FindControl("tbLastName"), TextBox) if somecondition = true then lblProductType.Visible = False tbLastName.Visible = true else lblProductType.Visible = true tbLastName.Visible = false end if End sub *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! |
| All times are GMT. The time now is 10:45 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.