473,473 Members | 1,857 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Object reference??

I am trying to assign a value from DataItem to a variable but keeping getting "
Object reference not set to an instance of an object" error message.

what i am missing?

public void create_ddl(object s, RepeaterItemEventArgs e)
{

string categoryName =
((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString();

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{

DropDownList dd = (DropDownList)e.Item.FindControl("ddl");

if(dd !=null)
{
dd.DataSource = bs.drPriority();
dd.DataTextField = "text";
dd.DataValueField = "value";
dd.DataBind();
dd.Items.FindByValue(dr["Priority"].ToString()).Selected
= true;

}

}
}
Nov 18 '05 #1
11 1371
huzz wrote:
I am trying to assign a value from DataItem to a variable but keeping
getting " Object reference not set to an instance of an object" error
message.

what i am missing?

public void create_ddl(object s, RepeaterItemEventArgs e)
{

string categoryName =
((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString();

if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{

DropDownList dd =
(DropDownList)e.Item.FindControl("ddl");

if(dd !=null)
{
dd.DataSource = bs.drPriority();
What is "bs" ??
dd.DataTextField = "text";
dd.DataValueField = "value";
dd.DataBind();

dd.Items.FindByValue(dr["Priority"].ToString()).Selected = true;

}

}
}


It would help if you specify the line the error is in.

Hans Kesting
Nov 18 '05 #2
Hi Hans

Here is the line no:
Line 57: string categoryName =
((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString();
"Hans Kesting" wrote:
huzz wrote:
I am trying to assign a value from DataItem to a variable but keeping
getting " Object reference not set to an instance of an object" error
message.

what i am missing?

public void create_ddl(object s, RepeaterItemEventArgs e)
{

string categoryName =
((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString();

if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{

DropDownList dd =
(DropDownList)e.Item.FindControl("ddl");

if(dd !=null)
{
dd.DataSource = bs.drPriority();


What is "bs" ??
dd.DataTextField = "text";
dd.DataValueField = "value";
dd.DataBind();

dd.Items.FindByValue(dr["Priority"].ToString()).Selected = true;

}

}
}


It would help if you specify the line the error is in.

Hans Kesting

Nov 18 '05 #3
e.Item.DataItem is null. The problem is you are checking for ItemType after
getting the categoryName. However, if you are in a headerTemplate or a
footerTemplate, e.Item.DataItem will be null. Simply move that code inside
your if statement:

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem){
string categoryName =
((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString();
...
}

should work

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"huzz" <hu**@discussions.microsoft.com> wrote in message
news:B4**********************************@microsof t.com...
Hi Hans

Here is the line no:
Line 57: string categoryName =
((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString();
"Hans Kesting" wrote:
huzz wrote:
I am trying to assign a value from DataItem to a variable but keeping
getting " Object reference not set to an instance of an object" error
message.

what i am missing?

public void create_ddl(object s, RepeaterItemEventArgs e)
{

string categoryName =
((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString();

if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{

DropDownList dd =
(DropDownList)e.Item.FindControl("ddl");

if(dd !=null)
{
dd.DataSource = bs.drPriority();


What is "bs" ??
dd.DataTextField = "text";
dd.DataValueField = "value";
dd.DataBind();

dd.Items.FindByValue(dr["Priority"].ToString()).Selected = true;

}

}
}


It would help if you specify the line the error is in.

Hans Kesting

Nov 18 '05 #4
karl thanks for your quick response.. after i moved the line of code inside
the if statement and now getting this message

"Specified cast is not valid. "

Line 64: string categoryName =
((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString();
"Karl Seguin" wrote:
e.Item.DataItem is null. The problem is you are checking for ItemType after
getting the categoryName. However, if you are in a headerTemplate or a
footerTemplate, e.Item.DataItem will be null. Simply move that code inside
your if statement:

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem){
string categoryName =
((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString();
...
}

should work

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"huzz" <hu**@discussions.microsoft.com> wrote in message
news:B4**********************************@microsof t.com...
Hi Hans

Here is the line no:
Line 57: string categoryName =
((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString();
"Hans Kesting" wrote:
huzz wrote:
> I am trying to assign a value from DataItem to a variable but keeping
> getting " Object reference not set to an instance of an object" error
> message.
>
> what i am missing?
>
> public void create_ddl(object s, RepeaterItemEventArgs e)
> {
>
> string categoryName =
> ((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString();
>
> if (e.Item.ItemType == ListItemType.Item ||
> e.Item.ItemType == ListItemType.AlternatingItem)
> {
>
> DropDownList dd =
> (DropDownList)e.Item.FindControl("ddl");
>
> if(dd !=null)
> {
> dd.DataSource = bs.drPriority();

What is "bs" ??

> dd.DataTextField = "text";
> dd.DataValueField = "value";
> dd.DataBind();
>
> dd.Items.FindByValue(dr["Priority"].ToString()).Selected = true;
>
> }
>
> }
> }

It would help if you specify the line the error is in.

Hans Kesting


Nov 18 '05 #5
What are you binding your repeater to?

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"huzz" <hu**@discussions.microsoft.com> wrote in message
news:0E**********************************@microsof t.com...
karl thanks for your quick response.. after i moved the line of code inside the if statement and now getting this message

"Specified cast is not valid. "

Line 64: string categoryName =
((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString();
"Karl Seguin" wrote:
e.Item.DataItem is null. The problem is you are checking for ItemType after getting the categoryName. However, if you are in a headerTemplate or a
footerTemplate, e.Item.DataItem will be null. Simply move that code inside your if statement:

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem){
string categoryName =
((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString();
...
}

should work

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"huzz" <hu**@discussions.microsoft.com> wrote in message
news:B4**********************************@microsof t.com...
Hi Hans

Here is the line no:
Line 57: string categoryName =
((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString();
"Hans Kesting" wrote:

> huzz wrote:
> > I am trying to assign a value from DataItem to a variable but keeping > > getting " Object reference not set to an instance of an object" error > > message.
> >
> > what i am missing?
> >
> > public void create_ddl(object s, RepeaterItemEventArgs e)
> > {
> >
> > string categoryName =
> > ((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString();
> >
> > if (e.Item.ItemType == ListItemType.Item ||
> > e.Item.ItemType == ListItemType.AlternatingItem)
> > {
> >
> > DropDownList dd =
> > (DropDownList)e.Item.FindControl("ddl");
> >
> > if(dd !=null)
> > {
> > dd.DataSource = bs.drPriority();
>
> What is "bs" ??
>
> > dd.DataTextField = "text";
> > dd.DataValueField = "value";
> > dd.DataBind();
> >
> > dd.Items.FindByValue(dr["Priority"].ToString()).Selected = true;
> >
> > }
> >
> > }
> > }
>
> It would help if you specify the line the error is in.
>
> Hans Kesting
>
>
>


Nov 18 '05 #6
The repeater is binded to datareader

"Karl Seguin" wrote:
What are you binding your repeater to?

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"huzz" <hu**@discussions.microsoft.com> wrote in message
news:0E**********************************@microsof t.com...
karl thanks for your quick response.. after i moved the line of code

inside
the if statement and now getting this message

"Specified cast is not valid. "

Line 64: string categoryName =
((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString();
"Karl Seguin" wrote:
e.Item.DataItem is null. The problem is you are checking for ItemType after getting the categoryName. However, if you are in a headerTemplate or a
footerTemplate, e.Item.DataItem will be null. Simply move that code inside your if statement:

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem){
string categoryName =
((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString();
...
}

should work

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"huzz" <hu**@discussions.microsoft.com> wrote in message
news:B4**********************************@microsof t.com...
> Hi Hans
>
> Here is the line no:
> Line 57: string categoryName =
> ((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString();
>
>
> "Hans Kesting" wrote:
>
> > huzz wrote:
> > > I am trying to assign a value from DataItem to a variable but keeping > > > getting " Object reference not set to an instance of an object" error > > > message.
> > >
> > > what i am missing?
> > >
> > > public void create_ddl(object s, RepeaterItemEventArgs e)
> > > {
> > >
> > > string categoryName =
> > > ((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString();
> > >
> > > if (e.Item.ItemType == ListItemType.Item ||
> > > e.Item.ItemType == ListItemType.AlternatingItem)
> > > {
> > >
> > > DropDownList dd =
> > > (DropDownList)e.Item.FindControl("ddl");
> > >
> > > if(dd !=null)
> > > {
> > > dd.DataSource = bs.drPriority();
> >
> > What is "bs" ??
> >
> > > dd.DataTextField = "text";
> > > dd.DataValueField = "value";
> > > dd.DataBind();
> > >
> > > dd.Items.FindByValue(dr["Priority"].ToString()).Selected = true;
> > >
> > > }
> > >
> > > }
> > > }
> >
> > It would help if you specify the line the error is in.
> >
> > Hans Kesting
> >
> >
> >


Nov 18 '05 #7
Try casting it to DbDataRecord (I think)

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"huzz" <hu**@discussions.microsoft.com> wrote in message
news:74**********************************@microsof t.com...
The repeater is binded to datareader

"Karl Seguin" wrote:
What are you binding your repeater to?

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"huzz" <hu**@discussions.microsoft.com> wrote in message
news:0E**********************************@microsof t.com...
karl thanks for your quick response.. after i moved the line of code

inside
the if statement and now getting this message

"Specified cast is not valid. "

Line 64: string categoryName =
((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString();
"Karl Seguin" wrote:

> e.Item.DataItem is null. The problem is you are checking for ItemType
after
> getting the categoryName. However, if you are in a headerTemplate
or a > footerTemplate, e.Item.DataItem will be null. Simply move that code

inside
> your if statement:
>
> if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
> ListItemType.AlternatingItem){
> string categoryName =
> ((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString();
> ...
> }
>
> should work
>
> Karl
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/
>
>
> "huzz" <hu**@discussions.microsoft.com> wrote in message
> news:B4**********************************@microsof t.com...
> > Hi Hans
> >
> > Here is the line no:
> > Line 57: string categoryName =
> > ((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString();
> >
> >
> > "Hans Kesting" wrote:
> >
> > > huzz wrote:
> > > > I am trying to assign a value from DataItem to a variable but

keeping
> > > > getting " Object reference not set to an instance of an object" error
> > > > message.
> > > >
> > > > what i am missing?
> > > >
> > > > public void create_ddl(object s, RepeaterItemEventArgs e)
> > > > {
> > > >
> > > > string categoryName =
> > > > ((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString();
> > > >
> > > > if (e.Item.ItemType == ListItemType.Item ||
> > > > e.Item.ItemType == ListItemType.AlternatingItem)
> > > > {
> > > >
> > > > DropDownList dd =
> > > > (DropDownList)e.Item.FindControl("ddl");
> > > >
> > > > if(dd !=null)
> > > > {
> > > > dd.DataSource = bs.drPriority();
> > >
> > > What is "bs" ??
> > >
> > > > dd.DataTextField = "text";
> > > > dd.DataValueField = "value";
> > > > dd.DataBind();
> > > >
> > > > dd.Items.FindByValue(dr["Priority"].ToString()).Selected =

true; > > > >
> > > > }
> > > >
> > > > }
> > > > }
> > >
> > > It would help if you specify the line the error is in.
> > >
> > > Hans Kesting
> > >
> > >
> > >
>
>
>


Nov 18 '05 #8
sorry karl i am very new to asp.net.. what is DbDataReader? can you show me
code?

Many thanks for your help

"Karl Seguin" wrote:
Try casting it to DbDataRecord (I think)

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"huzz" <hu**@discussions.microsoft.com> wrote in message
news:74**********************************@microsof t.com...
The repeater is binded to datareader

"Karl Seguin" wrote:
What are you binding your repeater to?

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"huzz" <hu**@discussions.microsoft.com> wrote in message
news:0E**********************************@microsof t.com...
> karl thanks for your quick response.. after i moved the line of code
inside
> the if statement and now getting this message
>
> "Specified cast is not valid. "
>
> Line 64: string categoryName =
> ((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString();
>
>
> "Karl Seguin" wrote:
>
> > e.Item.DataItem is null. The problem is you are checking for ItemType after
> > getting the categoryName. However, if you are in a headerTemplate or a > > footerTemplate, e.Item.DataItem will be null. Simply move that code
inside
> > your if statement:
> >
> > if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
> > ListItemType.AlternatingItem){
> > string categoryName =
> > ((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString();
> > ...
> > }
> >
> > should work
> >
> > Karl
> > --
> > MY ASP.Net tutorials
> > http://www.openmymind.net/
> >
> >
> > "huzz" <hu**@discussions.microsoft.com> wrote in message
> > news:B4**********************************@microsof t.com...
> > > Hi Hans
> > >
> > > Here is the line no:
> > > Line 57: string categoryName =
> > > ((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString();
> > >
> > >
> > > "Hans Kesting" wrote:
> > >
> > > > huzz wrote:
> > > > > I am trying to assign a value from DataItem to a variable but
keeping
> > > > > getting " Object reference not set to an instance of an object" error
> > > > > message.
> > > > >
> > > > > what i am missing?
> > > > >
> > > > > public void create_ddl(object s, RepeaterItemEventArgs e)
> > > > > {
> > > > >
> > > > > string categoryName =
> > > > > ((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString();
> > > > >
> > > > > if (e.Item.ItemType == ListItemType.Item ||
> > > > > e.Item.ItemType == ListItemType.AlternatingItem)
> > > > > {
> > > > >
> > > > > DropDownList dd =
> > > > > (DropDownList)e.Item.FindControl("ddl");
> > > > >
> > > > > if(dd !=null)
> > > > > {
> > > > > dd.DataSource = bs.drPriority();
> > > >
> > > > What is "bs" ??
> > > >
> > > > > dd.DataTextField = "text";
> > > > > dd.DataValueField = "value";
> > > > > dd.DataBind();
> > > > >
> > > > > dd.Items.FindByValue(dr["Priority"].ToString()).Selected = true; > > > > >
> > > > > }
> > > > >
> > > > > }
> > > > > }
> > > >
> > > > It would help if you specify the line the error is in.
> > > >
> > > > Hans Kesting
> > > >
> > > >
> > > >
> >
> >
> >


Nov 18 '05 #9
string categoryName =
((DbDataRecord)e.Item.DataItem)["FaultDesc"].ToString();

it's in the System.Data.Common namespace, so either add

using System.Data.Common atop your file, or do

string categoryName =
((System.Data.Common.DbDataRecord)e.Item.DataItem)["FaultDesc"].ToString();
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"huzz" <hu**@discussions.microsoft.com> wrote in message
news:45**********************************@microsof t.com...
sorry karl i am very new to asp.net.. what is DbDataReader? can you show me code?

Many thanks for your help

"Karl Seguin" wrote:
Try casting it to DbDataRecord (I think)

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"huzz" <hu**@discussions.microsoft.com> wrote in message
news:74**********************************@microsof t.com...
The repeater is binded to datareader

"Karl Seguin" wrote:

> What are you binding your repeater to?
>
> Karl
>
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/
>
>
> "huzz" <hu**@discussions.microsoft.com> wrote in message
> news:0E**********************************@microsof t.com...
> > karl thanks for your quick response.. after i moved the line of code > inside
> > the if statement and now getting this message
> >
> > "Specified cast is not valid. "
> >
> > Line 64: string categoryName =
> > ((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString();
> >
> >
> > "Karl Seguin" wrote:
> >
> > > e.Item.DataItem is null. The problem is you are checking for

ItemType
> after
> > > getting the categoryName. However, if you are in a headerTemplate
or a
> > > footerTemplate, e.Item.DataItem will be null. Simply move that

code > inside
> > > your if statement:
> > >
> > > if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
> > > ListItemType.AlternatingItem){
> > > string categoryName =
> > > ((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString();
> > > ...
> > > }
> > >
> > > should work
> > >
> > > Karl
> > > --
> > > MY ASP.Net tutorials
> > > http://www.openmymind.net/
> > >
> > >
> > > "huzz" <hu**@discussions.microsoft.com> wrote in message
> > > news:B4**********************************@microsof t.com...
> > > > Hi Hans
> > > >
> > > > Here is the line no:
> > > > Line 57: string categoryName =
> > > > ((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString();
> > > >
> > > >
> > > > "Hans Kesting" wrote:
> > > >
> > > > > huzz wrote:
> > > > > > I am trying to assign a value from DataItem to a variable but > keeping
> > > > > > getting " Object reference not set to an instance of an

object"
> error
> > > > > > message.
> > > > > >
> > > > > > what i am missing?
> > > > > >
> > > > > > public void create_ddl(object s, RepeaterItemEventArgs e)
> > > > > > {
> > > > > >
> > > > > > string categoryName =
> > > > > > ((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString(); > > > > > >
> > > > > > if (e.Item.ItemType == ListItemType.Item ||
> > > > > > e.Item.ItemType == ListItemType.AlternatingItem)
> > > > > > {
> > > > > >
> > > > > > DropDownList dd =
> > > > > > (DropDownList)e.Item.FindControl("ddl");
> > > > > >
> > > > > > if(dd !=null)
> > > > > > {
> > > > > > dd.DataSource = bs.drPriority();
> > > > >
> > > > > What is "bs" ??
> > > > >
> > > > > > dd.DataTextField = "text";
> > > > > > dd.DataValueField = "value";
> > > > > > dd.DataBind();
> > > > > >
> > > > > > dd.Items.FindByValue(dr["Priority"].ToString()).Selected =

true;
> > > > > >
> > > > > > }
> > > > > >
> > > > > > }
> > > > > > }
> > > > >
> > > > > It would help if you specify the line the error is in.
> > > > >
> > > > > Hans Kesting
> > > > >
> > > > >
> > > > >
> > >
> > >
> > >
>
>
>


Nov 18 '05 #10
Karl THANK U SO MUCH.. its working now :)

just wondering why it didn't work with DataRowView.. and what is DbDataRecord?

Many thanks again for your help..
PS: your article on databinding is exellent.. :)

"Karl Seguin" wrote:
string categoryName =
((DbDataRecord)e.Item.DataItem)["FaultDesc"].ToString();

it's in the System.Data.Common namespace, so either add

using System.Data.Common atop your file, or do

string categoryName =
((System.Data.Common.DbDataRecord)e.Item.DataItem)["FaultDesc"].ToString();
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"huzz" <hu**@discussions.microsoft.com> wrote in message
news:45**********************************@microsof t.com...
sorry karl i am very new to asp.net.. what is DbDataReader? can you show

me
code?

Many thanks for your help

"Karl Seguin" wrote:
Try casting it to DbDataRecord (I think)

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"huzz" <hu**@discussions.microsoft.com> wrote in message
news:74**********************************@microsof t.com...
> The repeater is binded to datareader
>
> "Karl Seguin" wrote:
>
> > What are you binding your repeater to?
> >
> > Karl
> >
> > --
> > MY ASP.Net tutorials
> > http://www.openmymind.net/
> >
> >
> > "huzz" <hu**@discussions.microsoft.com> wrote in message
> > news:0E**********************************@microsof t.com...
> > > karl thanks for your quick response.. after i moved the line of code > > inside
> > > the if statement and now getting this message
> > >
> > > "Specified cast is not valid. "
> > >
> > > Line 64: string categoryName =
> > > ((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString();
> > >
> > >
> > > "Karl Seguin" wrote:
> > >
> > > > e.Item.DataItem is null. The problem is you are checking for
ItemType
> > after
> > > > getting the categoryName. However, if you are in a headerTemplate or a
> > > > footerTemplate, e.Item.DataItem will be null. Simply move that code > > inside
> > > > your if statement:
> > > >
> > > > if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
> > > > ListItemType.AlternatingItem){
> > > > string categoryName =
> > > > ((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString();
> > > > ...
> > > > }
> > > >
> > > > should work
> > > >
> > > > Karl
> > > > --
> > > > MY ASP.Net tutorials
> > > > http://www.openmymind.net/
> > > >
> > > >
> > > > "huzz" <hu**@discussions.microsoft.com> wrote in message
> > > > news:B4**********************************@microsof t.com...
> > > > > Hi Hans
> > > > >
> > > > > Here is the line no:
> > > > > Line 57: string categoryName =
> > > > > ((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString();
> > > > >
> > > > >
> > > > > "Hans Kesting" wrote:
> > > > >
> > > > > > huzz wrote:
> > > > > > > I am trying to assign a value from DataItem to a variable but > > keeping
> > > > > > > getting " Object reference not set to an instance of an
object"
> > error
> > > > > > > message.
> > > > > > >
> > > > > > > what i am missing?
> > > > > > >
> > > > > > > public void create_ddl(object s, RepeaterItemEventArgs e)
> > > > > > > {
> > > > > > >
> > > > > > > string categoryName =
> > > > > > > ((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString(); > > > > > > >
> > > > > > > if (e.Item.ItemType == ListItemType.Item ||
> > > > > > > e.Item.ItemType == ListItemType.AlternatingItem)
> > > > > > > {
> > > > > > >
> > > > > > > DropDownList dd =
> > > > > > > (DropDownList)e.Item.FindControl("ddl");
> > > > > > >
> > > > > > > if(dd !=null)
> > > > > > > {
> > > > > > > dd.DataSource = bs.drPriority();
> > > > > >
> > > > > > What is "bs" ??
> > > > > >
> > > > > > > dd.DataTextField = "text";
> > > > > > > dd.DataValueField = "value";
> > > > > > > dd.DataBind();
> > > > > > >
> > > > > > > dd.Items.FindByValue(dr["Priority"].ToString()).Selected =
true;
> > > > > > >
> > > > > > > }
> > > > > > >
> > > > > > > }
> > > > > > > }
> > > > > >
> > > > > > It would help if you specify the line the error is in.
> > > > > >
> > > > > > Hans Kesting
> > > > > >
> > > > > >
> > > > > >
> > > >
> > > >
> > > >
> >
> >
> >
>


Nov 18 '05 #11
Thanks for the kind words, but clearly my databinding arcticle was missing a
key piece of information :)

As I say in the article, when you bind to a dataset, datatable or dataview,
the individual items are of type DataRowView.

What I didn't say, is when you bind to a datareader, the individual items
are of type DbDataRecord. DbDataRecord is the underlaying common type that
all rows of an DataReader (OledbDataReader, SqlDataReader, OracleDataReader)
are based on :)

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"huzz" <hu**@discussions.microsoft.com> wrote in message
news:4B**********************************@microsof t.com...
Karl THANK U SO MUCH.. its working now :)

just wondering why it didn't work with DataRowView.. and what is DbDataRecord?
Many thanks again for your help..
PS: your article on databinding is exellent.. :)

"Karl Seguin" wrote:
string categoryName =
((DbDataRecord)e.Item.DataItem)["FaultDesc"].ToString();

it's in the System.Data.Common namespace, so either add

using System.Data.Common atop your file, or do

string categoryName =
((System.Data.Common.DbDataRecord)e.Item.DataItem)["FaultDesc"].ToString();

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"huzz" <hu**@discussions.microsoft.com> wrote in message
news:45**********************************@microsof t.com...
sorry karl i am very new to asp.net.. what is DbDataReader? can you show
me
code?

Many thanks for your help

"Karl Seguin" wrote:

> Try casting it to DbDataRecord (I think)
>
> Karl
>
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/
>
>
> "huzz" <hu**@discussions.microsoft.com> wrote in message
> news:74**********************************@microsof t.com...
> > The repeater is binded to datareader
> >
> > "Karl Seguin" wrote:
> >
> > > What are you binding your repeater to?
> > >
> > > Karl
> > >
> > > --
> > > MY ASP.Net tutorials
> > > http://www.openmymind.net/
> > >
> > >
> > > "huzz" <hu**@discussions.microsoft.com> wrote in message
> > > news:0E**********************************@microsof t.com...
> > > > karl thanks for your quick response.. after i moved the line
of code
> > > inside
> > > > the if statement and now getting this message
> > > >
> > > > "Specified cast is not valid. "
> > > >
> > > > Line 64: string categoryName =
> > > > ((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString();
> > > >
> > > >
> > > > "Karl Seguin" wrote:
> > > >
> > > > > e.Item.DataItem is null. The problem is you are checking
for > ItemType
> > > after
> > > > > getting the categoryName. However, if you are in a

headerTemplate
> or a
> > > > > footerTemplate, e.Item.DataItem will be null. Simply move that code
> > > inside
> > > > > your if statement:
> > > > >
> > > > > if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType
== > > > > > ListItemType.AlternatingItem){
> > > > > string categoryName =
> > > > > ((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString();
> > > > > ...
> > > > > }
> > > > >
> > > > > should work
> > > > >
> > > > > Karl
> > > > > --
> > > > > MY ASP.Net tutorials
> > > > > http://www.openmymind.net/
> > > > >
> > > > >
> > > > > "huzz" <hu**@discussions.microsoft.com> wrote in message
> > > > > news:B4**********************************@microsof t.com...
> > > > > > Hi Hans
> > > > > >
> > > > > > Here is the line no:
> > > > > > Line 57: string categoryName =
> > > > > > ((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString(); > > > > > >
> > > > > >
> > > > > > "Hans Kesting" wrote:
> > > > > >
> > > > > > > huzz wrote:
> > > > > > > > I am trying to assign a value from DataItem to a variable but
> > > keeping
> > > > > > > > getting " Object reference not set to an instance of

an > object"
> > > error
> > > > > > > > message.
> > > > > > > >
> > > > > > > > what i am missing?
> > > > > > > >
> > > > > > > > public void create_ddl(object s, RepeaterItemEventArgs e) > > > > > > > > {
> > > > > > > >
> > > > > > > > string categoryName =
> > > > > > > >

((DataRowView)e.Item.DataItem).Row["FaultDesc"].ToString();
> > > > > > > >
> > > > > > > > if (e.Item.ItemType == ListItemType.Item ||
> > > > > > > > e.Item.ItemType == ListItemType.AlternatingItem)
> > > > > > > > {
> > > > > > > >
> > > > > > > > DropDownList dd =
> > > > > > > > (DropDownList)e.Item.FindControl("ddl");
> > > > > > > >
> > > > > > > > if(dd !=null)
> > > > > > > > {
> > > > > > > > dd.DataSource = bs.drPriority();
> > > > > > >
> > > > > > > What is "bs" ??
> > > > > > >
> > > > > > > > dd.DataTextField = "text";
> > > > > > > > dd.DataValueField = "value";
> > > > > > > > dd.DataBind();
> > > > > > > >
> > > > > > > > dd.Items.FindByValue(dr["Priority"].ToString()).Selected = > true;
> > > > > > > >
> > > > > > > > }
> > > > > > > >
> > > > > > > > }
> > > > > > > > }
> > > > > > >
> > > > > > > It would help if you specify the line the error is in.
> > > > > > >
> > > > > > > Hans Kesting
> > > > > > >
> > > > > > >
> > > > > > >
> > > > >
> > > > >
> > > > >
> > >
> > >
> > >
> >
>
>
>


Nov 18 '05 #12

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

Similar topics

6
by: Chris S. | last post by:
I'm trying to make a graphical editor and browser for Pickled files. One aspect I'm not sure about is how to detect multiple references to the same data. For instance, say I had the Pickled...
28
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()',...
11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
29
by: web1110 | last post by:
If I have 2 variables, A and B, referencing the same object and then do a A.Dispose(), what happens to B?
5
by: Michael Moreno | last post by:
Hello, In a class I have this code: public object Obj; If Obj is a COM object I would like to call in the Dispose() method the following code: ...
16
by: anonymous.user0 | last post by:
The way I understand it, if I have an object Listener that has registered as a listener for some event Event that's produced by an object Emitter, as long as Emitter is still allocated Listener...
7
by: TS | last post by:
I was under the assumption that if you pass an object as a param to a method and inside that method this object is changed, the object will stay changed when returned from the method because the...
3
by: User1014 | last post by:
A global variable is really just a property of the "Global Object", so what does that make a function defined in the global context? A method of the Global Object? ...
2
by: Ralph | last post by:
Hi I don't understand why it's not working: function schedule(imTop){ this.tdImagesTop = imTop; } schedule.prototype.selectEl = function() { alert(this.tdImagesTop);
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
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.