Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Datagrid Control (http://www.velocityreviews.com/forums/f60-asp-net-datagrid-control.html)
-   -   datagrid problem (http://www.velocityreviews.com/forums/t760174-datagrid-problem.html)

Jack Tonk 01-26-2004 11:09 PM

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



Girish Prabhu 01-27-2004 08:31 PM

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.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57