Hey,
Here is my problem. I wanted to create a very simply user control with a pre-formatted datagrid control.
Here is my .aspx code:
<%@ Control Language="vb" AutoEventWireup="false" Codebehind="importC.ascx.vb" Inherits="vaco2003_dev.importC" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<asp:datagrid id="dgrdReport" BorderWidth="1px" BorderStyle="Solid" BorderColor="#CCCCCC" Width="100%"
AutoGenerateColumns="False" GridLines="Horizontal" PageSize="50" runat="server">
<AlternatingItemStyle HorizontalAlign="Left" VerticalAlign="Top"></AlternatingItemStyle>
<ItemStyle Font-Size="11px" Font-Names="Arial,Helvetica,sans-serif" HorizontalAlign="Left"
ForeColor="Black" VerticalAlign="Top" BackColor="White"></ItemStyle>
<HeaderStyle Font-Size="11px" Font-Names="Arial,Helvetica,sans-serif" Font-Bold="True" HorizontalAlign="Left"
ForeColor="Black" VerticalAlign="Top" BackColor="#DFDFDF"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="cust_ref" HeaderText="Cust Ref #s">
<ItemStyle BackColor="#ECF0F4"></ItemStyle>
</asp:BoundColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton ID="hotListLink" CommandName="Edit" Runat="Server">
<%# Container.DataItem("hotListLink") %>
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
<asp:ButtonColumn Text="Select" DataTextField="file_no" HeaderText="File #"></asp:ButtonColumn>
<asp:BoundColumn DataField="ship_vessel" HeaderText="Shipper<br>Vessel">
<ItemStyle BackColor="#ECF0F4"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="container_no" HeaderText="Container #s"></asp:BoundColumn>
<asp:BoundColumn DataField="master_house" HeaderText="Master B/L<br>House B/L">
<ItemStyle BackColor="#ECF0F4"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="d2" HeaderText="Doc Recv.">
<HeaderStyle HorizontalAlign="Right" VerticalAlign="Top"></HeaderStyle>
<ItemStyle HorizontalAlign="Right" VerticalAlign="Top"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="d10" HeaderText="Dsp POI">
<HeaderStyle HorizontalAlign="Right" VerticalAlign="Top"></HeaderStyle>
<ItemStyle HorizontalAlign="Right" VerticalAlign="Top" BackColor="#ECF0F4"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="d11_d215" HeaderText="ETAPOE<br>ATAPOE">
<HeaderStyle HorizontalAlign="Right" VerticalAlign="Top"></HeaderStyle>
<ItemStyle HorizontalAlign="Right" VerticalAlign="Top"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="d16_d212" HeaderText="EnSub Date<br>Rls Date">
<HeaderStyle HorizontalAlign="Right" VerticalAlign="Top"></HeaderStyle>
<ItemStyle HorizontalAlign="Right" VerticalAlign="Top" BackColor="#ECF0F4"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="d24_d227" HeaderText="TrkNo<br>TrkPu">
<HeaderStyle HorizontalAlign="Right" VerticalAlign="Top"></HeaderStyle>
<ItemStyle HorizontalAlign="Right" VerticalAlign="Top"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="d108_d20" HeaderText="FDAt<br>FDAc">
<HeaderStyle HorizontalAlign="Right" VerticalAlign="Top"></HeaderStyle>
<ItemStyle HorizontalAlign="Right" VerticalAlign="Top" BackColor="#ECF0F4"></ItemStyle>
</asp:BoundColumn>
</Columns>
</asp:datagrid>
On the code behind, I have this:
Imports System
Imports System.Web
Imports System.Data
Imports System.Data.SqlClient
Public Class importC
Inherits System.Web.UI.UserControl
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents dgrdReport As System.Web.UI.WebControls.DataGrid
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Public Property datasource()
Get
Return dgrdReport.DataSource
End Get
Set(ByVal Value)
dgrdReport.DataSource = Value
End Set
End Property
End Class
However, when I call the control from another page like so:
Dim myDgrd As New importC
myDgrd.DataSource = source
myDgrd.DataBind()
I get the following error:
Object reference not set to an instance of an object
And it refers to the line in my control code behind where I set the value
Set(ByVal Value)
dgrdReport.DataSource = Value
End Set
What am I doing wrong?
Thanks for the help!
Bob Gibilaro