|
|
 |
| 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.
|
 |

December 24th, 2003, 09:40 AM
|
|
Registered User
|
|
Join Date: Dec 2003
Location: binghamton, ny, USA.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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>
|

December 29th, 2003, 04:01 PM
|
 |
Friend of Wrox
Points: 16,368, Level: 55 |
|
|
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,394
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
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.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |