DataList's EditCommand not being raised

Discussion in 'ASP .Net' started by Nathan Sokalski, Sep 4, 2005.

  1. I am attempting to raise the EditCommand event of a DataList when a Button
    in the ItemTemplate is clicked. Here is the HTML used for the ItemTemplate:

    <asp:Label id=lblEvent1 runat="server" EnableViewState="False"
    Width="175px" text='<%# DataBinder.Eval(Container,"DataItem.eventname")
    <asp:Label id=lblDescription1 runat="server" EnableViewState="False"
    Width="500px" text='<%# DataBinder.Eval(Container,"DataItem.description")
    <asp:Label id=lblDate1 runat="server" EnableViewState="False" Width="100px"
    text='<%# DataBinder.Eval(Container,"DataItem.eventdate","{0:d}")
    <asp:Label id=lblDetails1 runat="server" EnableViewState="False"
    Width="115px" text='<%# DataBinder.Eval(Container,"DataItem.details")
    <asp:Button id="btnEdit1" runat="server" Width="80px" Font-Bold="True"
    CausesValidation="False" Text="Edit Event" CommandName="edit"></asp:Button>

    Here is the event handler used to handle the EditCommand:

    Private Sub datEditEvents_EditCommand(ByVal source As Object, ByVal e As
    System.Web.UI.WebControls.DataListCommandEventArgs) Handles

    Label1.Text = "You clicked index " & CStr(e.Item.ItemIndex)

    datEditEvents.EditItemIndex = e.Item.ItemIndex

    Dim events As New DataSet

    Dim myconnection As New

    Dim cmdselect As New OracleCommand("SELECT * FROM eventlist ORDER BY
    eventdate", myconnection)

    Dim eventsadapter As New OracleDataAdapter(cmdselect)

    eventsadapter.SelectCommand = cmdselect

    eventsadapter.Fill(events, "eventlist")

    datEditEvents.DataSource = events


    End Sub

    Notice that I did include the CommandName="edit" in my Button control and
    the Handles clause in my event handler. When I click the button, nothing
    happens. I tested this using a Label which you see as the first line in my
    event handler. What am I forgetting? Is the CommandName attribute
    case-sensitive? Am I using the wrong value? Any help would be appreciated.
    Nathan Sokalski, Sep 4, 2005
    1. Advertisements

  2. Nathan Sokalski

    jasonkester Guest

    You seem to be going nuts with the EnableViewState="False" attributes.
    Are you sure you didn't throw one of those onto the DataList or the
    Form? That would be sufficient to unhook all your events.

    Jason Kester
    Expat Software Consulting Services
    jasonkester, Sep 5, 2005
    1. Advertisements

  3. Yes, I'm sure. One thing that I often do in my code to make it faster is
    make any Labels that I don't change EnableViewState="False" since the text
    is in the aspx file anyway. But here is the code for my opening DataList

    <asp:datalist id="datEditEvents" runat="server" Width="100%"

    As you can see, nothing there that I don't need (well, I guess it would
    still run without the width, but it might be kind of ugly). Any other ideas?
    Nathan Sokalski, Sep 5, 2005
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.