2

I want to use asp.net webforms model binding and nest a listview in a listview. Is this possible?

Currently I have set DataKeyNames on the parent and use the [Control] attribute in the SelectMethod and the method gets called for every row int the parent but the parameter is null.

Any help is appriciated.

<asp:ListView ID="Topics" runat="server"
    ItemType="Topic"
    SelectMethod="Topics_GetData"
    DataKeyNames="ID" >
    <EmptyDataTemplate>
                <div class="notice">
                    There are no Questions.
                </div>
            </EmptyDataTemplate>
    <ItemTemplate>
        <div><%# Item.TopicName %></div>

        <asp:ListView ID="QuestionSetListView" runat="server"
            ItemType="Question"
            SelectMethod="QuestionListView_GetData"
                 DataKeyNames="ID">
                <EmptyDataTemplate>
                    <div class="notice">
                        There are no Questions.
                    </div>
                </EmptyDataTemplate> ...

The select method :

QuestionListView_GetData([Control("Topics")] int? ID)

Any thoughts?

Thanks

1 Answer 1

3

Great to see someone doing cool things with Web Forms model binding. You can definitely do it, you just need to use a HiddenField to hold your ID,

<div><%# Item.TopicName %></div>
<asp:HiddenField ID="TopicID" runat="server" Value="<%# Item.ID %>" />
<asp:ListView ID="QuestionSetListView" runat="server"

And then refer to the TopicID in your Control Attribute

QuestionListView_GetData([Control("TopicID")] int? ID)
Sign up to request clarification or add additional context in comments.

2 Comments

Nice!!! now I need to figure out how do this with formview to insert these objects in the db.
Glad you liked it, a FormView works pretty much the same. I've done some examples with a FormView inside a ListView if you're interested? Have a look at my 'Navigation Identity for VS 2013.zip' sample available at navigation.codeplex.com/documentation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.