This is a migrated thread and some comments may be shown as answers.

Fire off ItemCommand from EmptyDataTemplate

1 Answer 88 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Amy
Top achievements
Rank 1
Amy asked on 21 Jul 2011, 08:38 PM
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:
<EmptyDataTemplate>
    <table>
        <tr>
            <td>
                <fieldset style="width: 800px">
                    <legend>SubSelection</legend>No Sub-Selections available.
                </fieldset>
            </td>
            <td style="width: 25%; text-align: right;">
                <asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="btnAdd_Click" CommandName="InitInsert"/>
            </td>
        </tr>
    </table>
</EmptyDataTemplate>

Here's the vb.net code for the button click event:
Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        RadListView1.InsertItemPosition = RadListViewInsertItemPosition.FirstItem
        RadListView1.Rebind()
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.

Thanks!

1 Answer, 1 is accepted

Sort by
0
Amy
Top achievements
Rank 1
answered on 25 Jul 2011, 07:43 PM
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.
Tags
ListView
Asked by
Amy
Top achievements
Rank 1
Answers by
Amy
Top achievements
Rank 1
Share this question
or