[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

web_team

2/18/2004 4:23:00 PM

Any advice on the following please?

Got a repeater on my page listing records from a database.
I slot a button in the last column which takes the record unique ID as
it's CommandName.
When the button is clicked it calls a function and passes the ID

So:

Sub FuncName(ByVal sender as system.object, ByVal e as
RepeaterCommandEventArgs)
Dim btn as Button
Dim IDdata
IDdata = btn.CommandName

IDdata is then used to query a database to return all the record
details for that unique ID

End FuncName.

I get the error of "Object reference not set to an instance of an
object". I'm definetly pulling a value out because the following test
prints the value to the screen.

TextBox.text = IDdata

Help
Thanks
Kevin




1 Answer

Alessandro Zifiglio

2/19/2004 1:00:00 PM

0

Dstl, What is button supposed to be ?

You have declared a button, and then you are tyring to access its
commandName attribute. Its normal you are getting that error. First of all
your button is not instantiated. You have only declared a button. To
instantiate it, you should use the new keyword on your button declaration
which will create a new button for you, which is not what you want anyway,
but will get rid of that error.

what you want to do instead is get the CommandName you stored within the
button in your repeater control, and get this CommandName when that button
is clicked, if i'm not wrong and your repeater exposes a few events for this
purpose.

For a click event fired you could use the onItemCommand method and code
here, this will fire for postbacks generated from within your repeater
control.

Sub R1_ItemCommand(Sender As Object, e As RepeaterCommandEventArgs)
dim IDData as string
IDData = CType(e.CommandSource, Button).CommandName
End Sub

or use the onItemCreated method which fires when the items within the
repeater control are created. Or the onItemDataBound method when the
repeater binds to a datasource --

"Dstl Web Team" <web_team@dstl.gov.uk> wrote in message
news:40338df4.22935390@146.80.9.44...
> Any advice on the following please?
>
> Got a repeater on my page listing records from a database.
> I slot a button in the last column which takes the record unique ID as
> it's CommandName.
> When the button is clicked it calls a function and passes the ID
>
> So:
>
> Sub FuncName(ByVal sender as system.object, ByVal e as
> RepeaterCommandEventArgs)
> Dim btn as Button
> Dim IDdata
> IDdata = btn.CommandName
>
> IDdata is then used to query a database to return all the record
> details for that unique ID
>
> End FuncName.
>
> I get the error of "Object reference not set to an instance of an
> object". I'm definetly pulling a value out because the following test
> prints the value to the screen.
>
> TextBox.text = IDdata
>
> Help
> Thanks
> Kevin
>
>
>
>