How do I wire up a button in a datalist template?

Discussion in 'ASP .Net' started by moondaddy, Apr 5, 2004.

  1. moondaddy

    moondaddy Guest

    using vb.net 1.1 I have a datalist and in it's item template I have 2
    buttons, 'edit' and 'ShipToThisAddress'. The edit button works fine and it
    opens up the edit template as it works with the edit command. But the how
    do I wire ShipToThisAddress button? Its going to submit the address ID to
    the database and do a redirect to another page. In the process of doing
    this, it will need to get the row index in the datalist so I can get the
    address ID from the datalist's keys collection.

    Thanks.

    --
     
    moondaddy, Apr 5, 2004
    #1
    1. Advertising

  2. moondaddy

    moondaddy Guest

    OK I partially solved my problem, but I didn't answer my question. In
    btnShipTo I used the item command by inputting 'item' in the command name
    property for btnShipTo in the designer. Then in the codebehind I used the
    following event to get the items key as a result of the button's the click
    event and do something with it.

    Private Sub dlAddresses_ItemCommand(ByVal source As Object, ByVal e As
    System.Web.UI.WebControls.DataListCommandEventArgs) Handles
    dlAddresses.ItemCommand
    Dim key As String = dlAddresses.DataKeys.Item(e.Item.ItemIndex)
    Console.WriteLine(key)
    End Sub

    HOWEVER

    suppose this command was already being used for something like Selecting the
    list item as the online documentation suggests. Then I would have to wire
    up btnShipTo from scratch. How would I do that?



    --

    "moondaddy" <> wrote in message
    news:%...
    > using vb.net 1.1 I have a datalist and in it's item template I have 2
    > buttons, 'edit' and 'ShipToThisAddress'. The edit button works fine and

    it
    > opens up the edit template as it works with the edit command. But the how
    > do I wire ShipToThisAddress button? Its going to submit the address ID to
    > the database and do a redirect to another page. In the process of doing
    > this, it will need to get the row index in the datalist so I can get the
    > address ID from the datalist's keys collection.
    >
    > Thanks.
    >
    > --
    >
    >
    >
     
    moondaddy, Apr 5, 2004
    #2
    1. Advertising

  3. If you fill CommandName and CommandArgument of LinkButton you can use
    ItemCommand event for handle event end get address ID for redirect!

    In this way you can write code similar this :

    [c# - CodeBehind]
    private void DataList1_ItemCommand(object source, DataListCommandEventArgs
    e)
    {
    if (e.CommandName.ToString() == "SkipTo")
    {
    string addressId = e.CommandArgument.ToString();
    }
    }

    [ASP:NET]
    <asp:DataList id="DataList1" runat="server">
    <ItemTemplate>
    <asp:LinkButton ID="lbtSkip" Runat=server CommandName="SkipTo"
    CommandArgument="<%# DataBinder.Eval(Container.DataItem, "AddressID")
    %>"></asp:LinkButton>
    </ItemTemplate>
    </asp:DataList>



    "moondaddy" <> wrote in message
    news:%...
    > using vb.net 1.1 I have a datalist and in it's item template I have 2
    > buttons, 'edit' and 'ShipToThisAddress'. The edit button works fine and

    it
    > opens up the edit template as it works with the edit command. But the how
    > do I wire ShipToThisAddress button? Its going to submit the address ID to
    > the database and do a redirect to another page. In the process of doing
    > this, it will need to get the row index in the datalist so I can get the
    > address ID from the datalist's keys collection.
    >
    > Thanks.
    >
    > --
    >
    >
    >
     
    Bruno Sirianni, Apr 5, 2004
    #3
  4. moondaddy

    moondaddy Guest

    Thanks that worked great. I didn't realize that you have multiple buttons
    use the item command event. Then in the item command event use a select
    case for the command argument to handle each button differently.

    --

    "Bruno Sirianni" <> wrote in message
    news:Lvkcc.24831$...
    > If you fill CommandName and CommandArgument of LinkButton you can use
    > ItemCommand event for handle event end get address ID for redirect!
    >
    > In this way you can write code similar this :
    >
    > [c# - CodeBehind]
    > private void DataList1_ItemCommand(object source,

    DataListCommandEventArgs
    > e)
    > {
    > if (e.CommandName.ToString() == "SkipTo")
    > {
    > string addressId = e.CommandArgument.ToString();
    > }
    > }
    >
    > [ASP:NET]
    > <asp:DataList id="DataList1" runat="server">
    > <ItemTemplate>
    > <asp:LinkButton ID="lbtSkip" Runat=server CommandName="SkipTo"
    > CommandArgument="<%# DataBinder.Eval(Container.DataItem, "AddressID")
    > %>"></asp:LinkButton>
    > </ItemTemplate>
    > </asp:DataList>
    >
    >
    >
    > "moondaddy" <> wrote in message
    > news:%...
    > > using vb.net 1.1 I have a datalist and in it's item template I have 2
    > > buttons, 'edit' and 'ShipToThisAddress'. The edit button works fine and

    > it
    > > opens up the edit template as it works with the edit command. But the

    how
    > > do I wire ShipToThisAddress button? Its going to submit the address ID

    to
    > > the database and do a redirect to another page. In the process of doing
    > > this, it will need to get the row index in the datalist so I can get the
    > > address ID from the datalist's keys collection.
    > >
    > > Thanks.
    > >
    > > --
    > >
    > >
    > >

    >
    >
     
    moondaddy, Apr 8, 2004
    #4
    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. Derrick

    wire enter to button click

    Derrick, Jun 29, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    335
    Derrick
    Jul 2, 2004
  2. Nevyn Twyll
    Replies:
    8
    Views:
    1,882
  3. Chris Newby
    Replies:
    1
    Views:
    600
    =?Utf-8?B?c2FyYQ==?=
    Feb 28, 2005
  4. AMT2K5
    Replies:
    0
    Views:
    365
    AMT2K5
    Mar 6, 2007
  5. Russ
    Replies:
    2
    Views:
    440
Loading...

Share This Page