Showing posts with label runat. Show all posts
Showing posts with label runat. Show all posts

Monday, March 26, 2012

Object reference not set to an instance of an object

HERE'S MY SCRIPT;

<%@dotnet.itags.org. Page Language="VB" Debug="True" CodePage="28599" %>
<%@dotnet.itags.org. Import NameSpace="System.Data" %>
<script runat="server">
Sub Page_Load(Obj As Object,E As EventArgs)
'DataSet Nesnesini Olustur -------
Dim ds as new DataSet("ornek_dataset")
'Tablo Olustur-----------
Dim musteritable as New DataTable("müsteriler")
'Tabloya Sutunlar Ekle--------
musteritable.Columns.Add ("ad",System.Type.GetType("System.String"))
musteritable.Columns.Add ("soyad",System.Type.GetType("System.String"))
musteritable.Columns.Add ("meslek",System.Type.GetType("System.String"))
musteritable.Columns.Add ("yas",System.Type.GetType("System.Int32"))
'Tabloyu DataSete Ekle --------
ds.Tables.Add(musteritable)
'Satir Olusturup, Veri Gir-------
Dim sira As DataRow = musteritable.NewRow
sira("ad")="Zafer"
sira("soyad")="Demirkol"
sira("meslek")="Web Programcýsý"
sira("yas")="33"
musteritable.rows.Add(sira)

Dim sira1 As DataRow = musteritable.NewRow
sira("ad")="Serdar"
sira("soyad")="Benli"
sira("meslek")="Pazarlamacý"
sira("yas")="32"
musteritable.rows.Add(sira1)

Dim sira2 As DataRow = musteritable.NewRow
sira("ad")="Denizhan"
sira("soyad")="Akkaya"
sira("meslek")="Muhasebeci"
sira("yas")="26"
musteritable.rows.Add(sira2)

Dim sira3 As DataRow = musteritable.NewRow
sira("ad")="Levent"
sira("soyad")="Demirkol"
sira("meslek")="Aþcý"
sira("yas")="28"
musteritable.rows.Add(sira3)
'----~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-----
Response.Write(ds.Tables("musteriler").rows(2)("ad") & "<br>")

Dim satir_3 As Datarow
satir_3 = ds.Tables("musteriler").rows(2)
Response.Write(satir_3(0) & "<br>")

Dim siralar As DataRowCollection
siralar=ds.Tables("musteriler").rows
Response.Write(siralar(2)("ad") & "<br>")

Dim tablo_degiskenim As DataTable
tablo_degiskenim = ds.Tables("musteriler")
Response.Write(tablo_degiskenim.rows(2)(0) & "<br>")

End sub
</script
AND THE ERROR PAGE;

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.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 43: musteritable.rows.Add(sira3)
Line 44: '----~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-----
Line 45: Response.Write(ds.Tables("musteriler").rows(2)("ad") & "<br>")
Line 46:
Line 47: Dim satir_3 As Datarow

Source File: D:\ASP.NET\dataset_olustur2.aspx Line: 45

I COULDN'T SEE THE MISTAKE, CAN YOU HELP ME?
THANX ...When you created the table, you called it "müsteriler".

Then, when you referenced it on Line 45, you called it "musteriler" ... with no accent ...
Oh yeah ! :)
...

I am bad at my native-lang "Turkish" just like I am bad at English ...
ü is a fuckin' letter in our keyboards ...

...

Thanx NewKid2 ...
If you find this happening too often, considerchanging the language of your computer.

Saturday, March 24, 2012

Object reference not set to an instance of an object

Hi,

I want to access in code-behind a label within the ItemTemplate of a
Formview.

<asp:FormView ID="FormView1" runat="server" DataKeyNames="id"
DataSourceID="SqlDataSource1" >
<ItemTemplate>
<asp:Label ID="nameLabel" runat="server" Text='<%# Bind("name")
%>'></asp:Label>

code-behind:
Dim name As String = CType(FormView1.FindControl("nameLabel"), Label).Text

I get the error: "Object reference not set to an instance of an object"

Could somebody tell me what's wrong in my code?
Thanks
BenTry

FormView1.Row.FindControl(...)

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Ben" <b@.bnwrote in message
news:%23obfXb8tHHA.3364@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

Hi,
>
I want to access in code-behind a label within the ItemTemplate of a
Formview.
>
<asp:FormView ID="FormView1" runat="server" DataKeyNames="id"
DataSourceID="SqlDataSource1" >
<ItemTemplate>
<asp:Label ID="nameLabel" runat="server" Text='<%# Bind("name")
%>'></asp:Label>
>
code-behind:
Dim name As String = CType(FormView1.FindControl("nameLabel"), Label).Text
>
>
I get the error: "Object reference not set to an instance of an object"
>
Could somebody tell me what's wrong in my code?
Thanks
Ben
>
>
>


On Jun 26, 2:06 pm, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@.mMvVpPsS.orgwrote:

Quote:

Originally Posted by

Try
>
FormView1.Row.FindControl(...)
>
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
>
"Ben" <b@.bnwrote in message
>
news:%23obfXb8tHHA.3364@.TK2MSFTNGP02.phx.gbl...
>

Quote:

Originally Posted by

Hi,


>

Quote:

Originally Posted by

I want to access in code-behind a label within the ItemTemplate of a
Formview.


>

Quote:

Originally Posted by

<asp:FormView ID="FormView1" runat="server" DataKeyNames="id"
DataSourceID="SqlDataSource1" >
<ItemTemplate>
<asp:Label ID="nameLabel" runat="server" Text='<%# Bind("name")
%>'></asp:Label>


>

Quote:

Originally Posted by

code-behind:
Dim name As String = CType(FormView1.FindControl("nameLabel"), Label).Text


>

Quote:

Originally Posted by

I get the error: "Object reference not set to an instance of an object"


>

Quote:

Originally Posted by

Could somebody tell me what's wrong in my code?
Thanks
Ben


hi
,

if (FormView1.DefaultMode == FormViewMode.ReadOnly)
{
Label lbl = (Label) FormView1.FindControl("nameLabel");
}

thanks
Masudur
As a general rule, it's a good idea to break up the statements in a single
line multi-expression code line into their own lines of code to facilitate
setting breakpoints and being able to examine values. The way you have it
now, it would be extremely difficult to tell what is going on.

-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder(BETA): http://www.blogmetafinder.com
"Ben" wrote:

Quote:

Originally Posted by

Hi,
>
I want to access in code-behind a label within the ItemTemplate of a
Formview.
>
<asp:FormView ID="FormView1" runat="server" DataKeyNames="id"
DataSourceID="SqlDataSource1" >
<ItemTemplate>
<asp:Label ID="nameLabel" runat="server" Text='<%# Bind("name")
%>'></asp:Label>
>
code-behind:
Dim name As String = CType(FormView1.FindControl("nameLabel"), Label).Text
>
>
I get the error: "Object reference not set to an instance of an object"
>
Could somebody tell me what's wrong in my code?
Thanks
Ben
>
>
>
>

Object reference not set to an instance of an object

Hi,
I want to access in code-behind a label within the ItemTemplate of a
Formview.
<asp:FormView ID="FormView1" runat="server" DataKeyNames="id"
DataSourceID="SqlDataSource1" >
<ItemTemplate>
<asp:Label ID="nameLabel" runat="server" Text='<%# Bind("name")
%>'></asp:Label>
code-behind:
Dim name As String = CType(FormView1.FindControl("nameLabel"), Label).Text
I get the error: "Object reference not set to an instance of an object"
Could somebody tell me what's wrong in my code?
Thanks
BenTry
FormView1.Row.FindControl(...)
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Ben" <b@.bn> wrote in message
news:%23obfXb8tHHA.3364@.TK2MSFTNGP02.phx.gbl...
> Hi,
> I want to access in code-behind a label within the ItemTemplate of a
> Formview.
> <asp:FormView ID="FormView1" runat="server" DataKeyNames="id"
> DataSourceID="SqlDataSource1" >
> <ItemTemplate>
> <asp:Label ID="nameLabel" runat="server" Text='<%# Bind("name")
> %>'></asp:Label>
> code-behind:
> Dim name As String = CType(FormView1.FindControl("nameLabel"), Label).Text
>
> I get the error: "Object reference not set to an instance of an object"
> Could somebody tell me what's wrong in my code?
> Thanks
> Ben
>
>
On Jun 26, 2:06 pm, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@.mMvVpPsS.org> wrote:
> Try
> FormView1.Row.FindControl(...)
> --
> Eliyahu Goldin,
> Software Developer & Consultant
> Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
> "Ben" <b@.bn> wrote in message
> news:%23obfXb8tHHA.3364@.TK2MSFTNGP02.phx.gbl...
>
>
>
>
>
>
hi
,
if (FormView1.DefaultMode == FormViewMode.ReadOnly)
{
Label lbl = (Label) FormView1.FindControl("nameLabel");
}
thanks
Masudur
As a general rule, it's a good idea to break up the statements in a single
line multi-expression code line into their own lines of code to facilitate
setting breakpoints and being able to examine values. The way you have it
now, it would be extremely difficult to tell what is going on.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder(BETA): http://www.blogmetafinder.com
"Ben" wrote:

> Hi,
> I want to access in code-behind a label within the ItemTemplate of a
> Formview.
> <asp:FormView ID="FormView1" runat="server" DataKeyNames="id"
> DataSourceID="SqlDataSource1" >
> <ItemTemplate>
> <asp:Label ID="nameLabel" runat="server" Text='<%# Bind("name")
> %>'></asp:Label>
> code-behind:
> Dim name As String = CType(FormView1.FindControl("nameLabel"), Label).Text
>
> I get the error: "Object reference not set to an instance of an object"
> Could somebody tell me what's wrong in my code?
> Thanks
> Ben
>
>

Object reference not set to an instance of an object

Hi,
I want to access in code-behind a label within the ItemTemplate of a
Formview.
<asp:FormView ID="FormView1" runat="server" DataKeyNames="id"
DataSourceID="SqlDataSource1" >
<ItemTemplate>
<asp:Label ID="nameLabel" runat="server" Text='<%# Bind("name")
%>'></asp:Label>
code-behind:
Dim name As String = CType(FormView1.FindControl("nameLabel"), Label).Text
I get the error: "Object reference not set to an instance of an object"
Could somebody tell me what's wrong in my code?
Thanks
BenHi Ben,
The direct answer is: nothing wrong.
It's probably an issue outside given code. Checks FormView1.Row and FormView
1.DataItem
are not null. If yes then be sure you have at least one record in FormView1'
s
source and DataBind is performed on the FormView1. You cannot retrieve contr
ols
if they are not processed.
Kind Regards, Alex Meleta
[TechBlog] http://devkids.blogspot.com
B> FormView1.FindControl("nameLabel")
B>