p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > ASP.NET and ASP > Other ASP.NET > ASP.NET 1.x and 2.0 Application Design
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0.

Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.x and 2.0 Application Design section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 24th, 2003, 09:40 AM
Registered User
Points: 21, Level: 1
Points: 21, Level: 1 Points: 21, Level: 1 Points: 21, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2003
Location: binghamton, ny, USA.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default ASP datagrid template textbox question

I want to be able to change the backcolor of a textbox in a datagrid dynamically by using the following onItemDataBound subroutine, but I am not sure of what the correct syntex is. Can someone help?

When I run this code as is, I get the following error:

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

It highlights this section of code as the error

 tbox.BackColor = Color.Aqua



Public Sub DG_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dg.ItemDataBound

if e.item.cells(0).text="5" then

        Dim tbox As TextBox = CType(e.Item.Cells(1).FindControl("Textbox_payment "), TextBox)
        tbox.BackColor = Color.aqua
end if

End Sub


This is my html of the datagrid

<ASPATAGRID id="dg" runat="server" GridLines="Both" AutoGenerateColumns="false" onItemDataBound="dg_itemdatabound">

<Columns>
<asp:BoundColumn DataField="order_no" HeaderText="Order Number"></asp:BoundColumn>

<asp:TemplateColumn HeaderText="Payment">
     <ItemTemplate>
    <asp:TextBox Runat="server" id="Textbox_payment" Text='<%#DataBinder.Eval (Container.DataItem, "payment") %>'></asp:TextBox>
     </ItemTemplate>
</asp:TemplateColumn>

</Columns>
</ASPATAGRID>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old December 29th, 2003, 04:01 PM
planoie's Avatar
Friend of Wrox
Points: 16,368, Level: 55
Points: 16,368, Level: 55 Points: 16,368, Level: 55 Points: 16,368, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,394
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Sounds like it's not finding the control correctly. You could try this instead seeing as you know exactly where the control is in the datagrid item cell:

Dim tbox As TextBox = CType(e.Item.Cells(1).Controls(0), TextBox)


Peter
------------------------------------------------------
Work smarter, not harder.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Change Text of Textbox inside Template DarkForce ASP.NET 2.0 Basics 2 June 17th, 2007 01:49 PM
Datagrid Item Template question dparsons ASP.NET 1.0 and 1.1 Professional 3 March 14th, 2007 10:08 AM
DataGrid Updates asp:textbox rjirak BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 2 May 1st, 2006 06:36 AM
ASP.Net:using Radio Button as template in Datagrid mishi ASP.NET 1.1 3 April 10th, 2005 04:41 PM
ASP.NET DataGrid Question desmond047 General .NET 1 August 25th, 2004 02:51 AM



All times are GMT -4. The time now is 12:05 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc