Fire off ItemCommand from EmptyDataTemplate

2 posts, 0 answers
  1. Amy
    Amy avatar
    113 posts
    Member since:
    Aug 2010

    Posted 21 Jul 2011 Link to this post

    Hi!  How can I go from displaying an EmptyDataTemplate to an ItemTemplate when a user clicks a button? 

    Currently I have an 'Add' button in the EmptyDataTemplate of a RadListView.  I want the user to click the 'Add' button and have the ItemTemplate display (which has various fields for user input).

    Here's the aspx code for the EmptyDataTemplate:
                    <fieldset style="width: 800px">
                        <legend>SubSelection</legend>No Sub-Selections available.
                <td style="width: 25%; text-align: right;">
                    <asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="btnAdd_Click" CommandName="InitInsert"/>

    Here's the code for the button click event:
    Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs)
            RadListView1.InsertItemPosition = RadListViewInsertItemPosition.FirstItem
    End Sub

    I can step through the code when debugging, but nothing happens when the 'Add' button is clicked.

    I also have the same 'Add' button on the EditItemTemplate with a value of 'InitInsert' for the 'CommandName'.  This button works fine since the EditItemTemplate fires off the RadListView ItemCommand routine.  In the ItemCommand routine for the 'InitInsert' command I have the same 2 lines of code used for the button click.

    I'm not understanding why this doesn't work for the button click event, and was wondering if someone could explain it to me or provide an alternate solution.

  2. Amy
    Amy avatar
    113 posts
    Member since:
    Aug 2010

    Posted 25 Jul 2011 Link to this post

    I figured out the solution.  In the 'Add' button declaration on the aspx page I had both the 'OnClick' and 'CommandName'.  I removed the 'OnClick' from the button declaration, and it now works as expected.

    Here's the aspx code for the button now:
    <asp:Button ID="btnAdd" runat="server" Text="Add" CommandName="InitInsert" />

    In the code behind I no longer use/need the 'OnClick' event as the functionality needed is handled by the RadListView's ItemCommand.
Back to Top