473,320 Members | 1,600 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Can't FindControl in DataGrid

I get this error:

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

And this is the subroutine that throws it:
Protected Sub DataUpdate(ByVal Sender As Object, _
ByVal E As DataGridCommandEventArgs)

Label1.Text = CType(E.Item.FindControl("DropDownList1"),
DropDownList).SelectedItem.Text

' Save TempValue to DB
End Sub

The dropdownlist is in a datagrid template:

<asp:datagrid id="DataGrid1" runat="server"
AutoGenerateColumns="False" oncancelcommand="DataCancel"
onupdatecommand="DataUpdate" datakeyfield="tourdate"
BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px"
BackColor="White" CellPadding="3" GridLines="Horizontal"
oneditcommand="DataEdit">
<Columns>
<asp:EditCommandColumn
ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel"
EditText="Edit"></asp:EditCommandColumn>
<asp:TemplateColumn
HeaderText="EditColumn">
<ItemTemplate>
<asp:Label id=Label2
runat="server" Text='<%# Container.DataItem("tourdate") %>'>Label
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList
id=DropDownList1 runat="server" DataSource="<%# dbView %>"
DataTextField="tourDate" DataMember="spTours" DataValueField="id">
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="tourDate"
HeaderText="Date"></asp:BoundColumn>
</Columns>
</asp:datagrid>

Everything else is working, the datagrid shows the data. The dropdown
box is populated. I can pick a value. But when I click the update link
on the datagrid, it throws the error.

Nov 20 '05 #1
1 3286
I changed it to:

Sub UpdateCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
DataGrid1.UpdateCommand
Dim ddl As New DropDownList()
ddl = e.Item.FindControl("DropDownList1")
Label1.Text = ddl.SelectedItem.Text
End Sub
and I get the same error:

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

Jim Bayers <sp**@spamity.spam> wrote in
news:Xn*****************************@128.196.120.1 31:
I get this error:

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

And this is the subroutine that throws it:
Protected Sub DataUpdate(ByVal Sender As Object, _
ByVal E As DataGridCommandEventArgs)

Label1.Text = CType(E.Item.FindControl("DropDownList1"),
DropDownList).SelectedItem.Text

' Save TempValue to DB
End Sub

The dropdownlist is in a datagrid template:

<asp:datagrid id="DataGrid1" runat="server"
AutoGenerateColumns="False" oncancelcommand="DataCancel"
onupdatecommand="DataUpdate" datakeyfield="tourdate"
BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px"
BackColor="White" CellPadding="3" GridLines="Horizontal"
oneditcommand="DataEdit">
<Columns>
<asp:EditCommandColumn
ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel"
EditText="Edit"></asp:EditCommandColumn>
<asp:TemplateColumn
HeaderText="EditColumn">
<ItemTemplate>
<asp:Label id=Label2
runat="server" Text='<%# Container.DataItem("tourdate") %>'>Label
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList
id=DropDownList1 runat="server" DataSource="<%# dbView %>"
DataTextField="tourDate" DataMember="spTours" DataValueField="id">
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="tourDate"
HeaderText="Date"></asp:BoundColumn>
</Columns>
</asp:datagrid>

Everything else is working, the datagrid shows the data. The dropdown
box is populated. I can pick a value. But when I click the update
link on the datagrid, it throws the error.


Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bob Rosen | last post by:
The description given in "Customizing Items Dynamically in the DataList or DataGrid Web Server Control" (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vbCode/...
2
by: Stan | last post by:
This is how I access Pieces field in my editable datargid during Update event: protected void grdMain_OnUpdate(Object sender, DataGridCommandEventArgs e) { string Pieces = ((TextBox)...
5
by: Stan | last post by:
I would like my header column span multiple columns, for example: Date Ready Open Close --------------------------- 08/06 10 am 5pm How can I do that? Thanks,
9
by: Max | last post by:
How do I reference a datagrid on a page from a user control on that page? In my user control, I'd like to have something like this... MyDataGrid being on the page, not in the user control... I...
1
by: bill yeager | last post by:
I have a datagrid control within a datalist control. When I try and do a "Find" on the control, the object comes back with nothing and then my pgm crashes. I am 100% sure that my datagird inside...
1
by: bill yeager | last post by:
I have a radiobuttonlist inside a datalist. I also have a datagrid inside the datalist. The data and the controls are rendering just fine. However, I need to find these controls inside the...
1
by: bill yeager | last post by:
I did some more debugging and found the following: 1) I placed the following code in the button event just to see if I could cycle thru the datagrid control collection: <code> Dim strhello As...
1
by: tshad | last post by:
I am using sample code from C# and am trying to convert it to VB.Net in my aspx page. This works in C#: DataGrid oGrid = (DataGrid)oItem.FindControl("DataGrid1"); I have tried all kinds of...
1
by: Luis Esteban Valencia | last post by:
Hello. I have a datagird with textboxes on a column item template, I also have 2 other columns that are hidden and I want to retrieve his value. But I havent found how to do it. Thanks very much...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.