Handling a button in repeater

Discussion in 'ASP .Net Web Controls' started by Dstl Web Team, Feb 18, 2004.

  1. 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
     
    Dstl Web Team, Feb 18, 2004
    #1
    1. Advertising

  2. 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" <> 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
    >
    >
    >
    >
     
    Alessandro Zifiglio, Feb 19, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mauritsius
    Replies:
    1
    Views:
    2,831
    John Saunders
    Dec 17, 2004
  2. Replies:
    0
    Views:
    876
  3. Replies:
    0
    Views:
    2,902
  4. Replies:
    1
    Views:
    7,047
    Karl Seguin
    Aug 10, 2005
  5. Imran Aziz

    Handling link button in repeater control

    Imran Aziz, Sep 2, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    1,863
    Imran Aziz
    Sep 2, 2005
Loading...

Share This Page