473,549 Members | 2,531 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataList DataBind - NullReferenceEx ception

This is killing me, I've been trying to figure this out for 2 days.

When I click on the linkbutton, it executes the GetData(int) method to set
the DataSource. The FAILURE is when it tries to call databind
(sender.DataBin d();
in NeedList_ItemCo mmand method). The error message is at the bottom of this
message (System.NullRef erenceException )

Can anyone else see anything wrong with this? (I've included all relevant
code, stored procedure and table)
This datalist is within a selecteditemtem plate...FYI....
---------------------------ASP.NET Code----------------------------

<asp:datalist id="TechList" runat="server" DataSource='<%#
GetData((int)Da taBinder.Eval(C ontainer.DataIt em, "NeedID")) %>'
RepeatDirection ="Vertical" repeatcolumns=" 1" Width="100%" CellPadding="0"
cellspacing="0" OnItemCommand=" NeedList_ItemCo mmand">
<headertemplate >
</headertemplate>
<itemtemplate >
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="100">
<asp:linkbutt on id="Linkbutton3 " runat="server" Text='<%#
DataBinder.Eval (Container.Data Item, "NeedID") %>'/>
</td>
</tr>
</table>
</itemtemplate>
</asp:datalist>

---------------------------Source Code----------------------------

protected void NeedList_ItemCo mmand(object Sender, DataListCommand EventArgs
e)
{
// change the selected index of Datalist
string cmd = ((LinkButton)e. CommandSource). CommandName;
DataList sender = (DataList)Sende r;
if (cmd == "select")
sender.Selected Index = e.Item.ItemInde x;

// re-bind to display info with new selected index.
//sender.DataSour ce = GetEnablingTech s((int)ViewStat e[_needID]);
sender.DataSour ce = GetData((int)Vi ewState[_needID]);

//******This is where it is failing******** **
sender.DataBind ();
}


protected DrillDownReport Collection GetData(int needID)
{
// only use the needID in session if it doesn't exist.
if (needID == 0)
needID = (int)ViewState[_needID];

return DrillDownReport .GetData(needID );
}

public static DrillDownReport Collection GetData(int needID)
{
DataSet dsData = SqlHelper.Execu teDataset(
ConfigurationSe ttings.AppSetti ngs[Global.CfgKeyCo nnString],
"WN_GetAllNeeds ");
DrillDownReport Collection items = new DrillDownReport Collection();

foreach(DataRow row in dsData.Tables[0].Rows)
{
DrillDownReport item = new DrillDownReport ();
item.EnableTech ID = Convert.ToInt32 (row["NeedID"].ToString());
item.EnableTech Name = row["NeedName"].ToString();
items.Add(item) ;
}

return items;
}

---------------------------Stored Procedure----------------------------

CREATE PROCEDURE WN_GetAllNeeds

AS

SELECT * FROM WN_Needs
GO

---------------------------Table----------------------------

CREATE TABLE [WN_Needs] (
[NeedID] [int] NOT NULL ,
[NeedName] [char] (50) COLLATE SQL_Latin1_Gene ral_CP1_CI_AS NULL
)
) ON [PRIMARY]
GO

---------------------------Error Message----------------------------

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

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

Source Error:
Line 56: </td>
Line 57: <td>
Line 58: <asp:datalist id="TechList" runat="server"
DataSource='<%# GetData((int)Da taBinder.Eval(C ontainer.DataIt em, "NeedID"))
%>' RepeatDirection ="Vertical" repeatcolumns=" 1" Width="100%" CellPadding="0"
cellspacing="0" OnItemCommand=" NeedList_ItemCo mmand">
Line 59: <headertemplate >
Line 60:
Source File: c:\inetpub\wwwr oot\TamTest\Dri llDown.aspx Line: 58

Stack Trace:
[NullReferenceEx ception: Object reference not set to an instance of an
object.]
ASP.DrillDown_a spx.__DataBind_ _control8(Objec t sender, EventArgs e) in
c:\inetpub\wwwr oot\TamTest\Dri llDown.aspx:58
System.Web.UI.C ontrol.OnDataBi nding(EventArgs e) +66
System.Web.UI.W ebControls.Base DataList.OnData Binding(EventAr gs e) +9
System.Web.UI.W ebControls.Base DataList.DataBi nd() +23
ASPNET.StarterK it.Reports.Dril lDown.NeedList_ ItemCommand(Obj ect Sender,
DataListCommand EventArgs e) in c:\inetpub\wwwr oot\tamtest\dri lldown.aspx.cs: 89
System.Web.UI.W ebControls.Data List.OnItemComm and(DataListCom mandEventArgs
e) +110
System.Web.UI.W ebControls.Data List.OnBubbleEv ent(Object source, EventArgs
e) +60
System.Web.UI.C ontrol.RaiseBub bleEvent(Object source, EventArgs args) +26
System.Web.UI.W ebControls.Data ListItem.OnBubb leEvent(Object source,
EventArgs e) +100
System.Web.UI.C ontrol.RaiseBub bleEvent(Object source, EventArgs args) +26
System.Web.UI.W ebControls.Link Button.OnComman d(CommandEventA rgs e) +121

System.Web.UI.W ebControls.Link Button.System.W eb.UI.IPostBack EventHandler.Ra isePostBackEven t(String eventArgument) +115
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +138
System.Web.UI.P age.ProcessRequ estMain() +1292

Dec 7 '05 #1
1 2929
Previous Message had a mistake, please use this one to answer my question:
This is killing me, I've been trying to figure this out for 2 days.

When I click on the linkbutton, it executes the GetData(int) method to set
the DataSource. The FAILURE is when it tries to call databind
(sender.DataBin d();
in NeedList_ItemCo mmand method). The error message is at the bottom of this
message (System.NullRef erenceException )

Can anyone else see anything wrong with this? (I've included all relevant
code, stored procedure and table)
This datalist is within a selecteditemtem plate...FYI....
---------------------------ASP.NET Code----------------------------

<asp:datalist id="TechList" runat="server" DataSource='<%#
GetData((int)Da taBinder.Eval(C ontainer.DataIt em, "NeedID")) %>'
RepeatDirection ="Vertical" repeatcolumns=" 1" Width="100%" CellPadding="0"
cellspacing="0" OnItemCommand=" NeedList_ItemCo mmand">
<headertemplate >
</headertemplate>
<itemtemplate >
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="100">
<asp:linkbutt on id="Linkbutton3 " runat="server" Text='<%#
DataBinder.Eval (Container.Data Item, "NeedID") %>'/>
</td>
</tr>
</table>
</itemtemplate>
</asp:datalist>

---------------------------Source Code----------------------------

protected void NeedList_ItemCo mmand(object Sender, DataListCommand EventArgs
e)
{
// change the selected index of Datalist
string cmd = ((LinkButton)e. CommandSource). CommandName;
DataList sender = (DataList)Sende r;
if (cmd == "select")
sender.Selected Index = e.Item.ItemInde x;

// re-bind to display info with new selected index.
//sender.DataSour ce = GetData((int)Vi ewState[_needID]);
sender.DataSour ce = GetData((int)Vi ewState[_needID]);

//******This is where it is failing******** **
sender.DataBind ();
}


protected DrillDownReport Collection GetData(int needID)
{
// only use the needID in session if it doesn't exist.
if (needID == 0)
needID = (int)ViewState[_needID];

return DrillDownReport .GetData(needID );
}

public static DrillDownReport Collection GetData(int needID)
{
DataSet dsData = SqlHelper.Execu teDataset(
ConfigurationSe ttings.AppSetti ngs[Global.CfgKeyCo nnString],
"WN_GetAllNeeds ");
DrillDownReport Collection items = new DrillDownReport Collection();

foreach(DataRow row in dsData.Tables[0].Rows)
{
DrillDownReport item = new DrillDownReport ();
item.NeedID = Convert.ToInt32 (row["NeedID"].ToString());
item.NeedName = row["NeedName"].ToString();
items.Add(item) ;
}

return items;
}

---------------------------Stored Procedure----------------------------

CREATE PROCEDURE WN_GetAllNeeds

AS

SELECT * FROM WN_Needs
GO

---------------------------Table----------------------------

CREATE TABLE [WN_Needs] (
[NeedID] [int] NOT NULL ,
[NeedName] [char] (50) COLLATE SQL_Latin1_Gene ral_CP1_CI_AS NULL
)
) ON [PRIMARY]
GO

---------------------------Error Message----------------------------

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

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

Source Error:
Line 56: </td>
Line 57: <td>
Line 58: <asp:datalist id="TechList" runat="server"
DataSource='<%# GetData((int)Da taBinder.Eval(C ontainer.DataIt em, "NeedID"))
%>' RepeatDirection ="Vertical" repeatcolumns=" 1" Width="100%" CellPadding="0"
cellspacing="0" OnItemCommand=" NeedList_ItemCo mmand">
Line 59: <headertemplate >
Line 60:
Source File: c:\inetpub\wwwr oot\TamTest\Dri llDown.aspx Line: 58

Stack Trace:
[NullReferenceEx ception: Object reference not set to an instance of an
object.]
ASP.DrillDown_a spx.__DataBind_ _control8(Objec t sender, EventArgs e) in
c:\inetpub\wwwr oot\TamTest\Dri llDown.aspx:58
System.Web.UI.C ontrol.OnDataBi nding(EventArgs e) +66
System.Web.UI.W ebControls.Base DataList.OnData Binding(EventAr gs e) +9
System.Web.UI.W ebControls.Base DataList.DataBi nd() +23
ASPNET.StarterK it.Reports.Dril lDown.NeedList_ ItemCommand(Obj ect Sender,
DataListCommand EventArgs e) in c:\inetpub\wwwr oot\tamtest\dri lldown.aspx.cs: 89
System.Web.UI.W ebControls.Data List.OnItemComm and(DataListCom mandEventArgs
e) +110
System.Web.UI.W ebControls.Data List.OnBubbleEv ent(Object source, EventArgs
e) +60
System.Web.UI.C ontrol.RaiseBub bleEvent(Object source, EventArgs args) +26
System.Web.UI.W ebControls.Data ListItem.OnBubb leEvent(Object source,
EventArgs e) +100
System.Web.UI.C ontrol.RaiseBub bleEvent(Object source, EventArgs args) +26
System.Web.UI.W ebControls.Link Button.OnComman d(CommandEventA rgs e) +121

System.Web.UI.W ebControls.Link Button.System.W eb.UI.IPostBack EventHandler.Ra isePostBackEven t(String eventArgument) +115
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +138
System.Web.UI.P age.ProcessRequ estMain() +1292
Dec 7 '05 #2

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

Similar topics

2
467
by: Antonio D'Ottavio | last post by:
Good Morning, In my web page I've a datalist that is sourced by a database, the problem is that I want that one of the column of the datalist contain a dropdownbox that also is sourced by a table in the database. <asp:DropDownList id="ComboTipoPartita" runat="server" DataValueField="IDTipoPartita" DataTextField="DescrizioneTipoPartita"...
0
1249
by: Antonio D'Ottavio | last post by:
Good Morning, In my web page I've a datalist that is sourced by a database, the problem is that I want that one of the column of the datalist contain a dropdownbox that also is sourced by a table in the database. The problem is is the error : System.NullReferenceException: Reference to an Object not setted on a object instance
1
1759
by: pete K | last post by:
Is it possible in asp.net to have a datalist in the itemtemplate of another datalist? For example: <asp:datalist id="MyList" runat="server"> <ItemTemplate> <table border="0" width="300"> <tr> <td><%# DataBinder.Eval(Container.DataItem, "title") %></td>
2
2057
by: cindy | last post by:
When my datalist loads I am trying to make the checked value in a radio button group reflect which value is stored in the data and then fire and event when the CheckChanged event fires. private void InitializeComponent() { if(!Page.IsPostBack){ this.ds = new System.Data.DataSet(); this.daListHW.DataSource=ds; this.daListHW.DataBind();}
3
2204
by: asadikhan | last post by:
Hi, I am trying to use a datalist to edit data in a MySql database as follows. For now I just want to be able to get the changes to be made on the dataset. Here is my code: using System; using System.Configuration; using System.Collections; using System.ComponentModel;
3
10286
by: Mirek Endys | last post by:
I have DataList as part of DataList item. DataList in DataList. The parent DataList working well including Edit command, that shows Edit template and correctly bind the data into edit template (where is the child DataList).... But in case I want to make Edit in this child DataList it is not working... No edit template showed... :( this is...
16
12135
by: Vikas Kumar | last post by:
i am selectin some data from database and through reader showing it in datalist as above now for radio buttons i have single column which returns 1,2,3 and according to that i want one of above radio button to be preselected in this datalist how can i do that doing something like this but this gives error "The type or namespace name 'rdbtn'...
5
4756
by: Vikas Kumar | last post by:
i had coded like this <ItemTemplate> <table width="100%"> <tr width="100%"> <td width="25%"><%#DataBinder.Eval(Container.DataItem,"FName")%></td> <td width="25%"><input type=text name="txtPass" value='<%#DataBinder.Eval(Container.DataItem,"Passwd")%>'></td> <td width="45%" align="left">
3
2800
by: Crazy Cat | last post by:
Hi all, I am developing an asp.net 2.0 application in Visual Studio 2005. On my page I have a simple datalist that is bound programmatically to a collection of simple objects. On this page I need to control the visibility of a textbox based on a dropdown selection in the datalist's edititem template. To do this, I registered a client script...
0
7457
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7723
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7965
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7817
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6051
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3504
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3487
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1063
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.