J
Jim Bayers
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
ropDownList
id=DropDownList1 runat="server" DataSource="<%# dbView %>"
DataTextField="tourDate" DataMember="spTours" DataValueField="id">
</asp
ropDownList>
</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.
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

id=DropDownList1 runat="server" DataSource="<%# dbView %>"
DataTextField="tourDate" DataMember="spTours" DataValueField="id">
</asp

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