<p>I have a Question class:</p>

<pre><code>class Question {
    public int QuestionNumber { get; set; }
    public string Question { get; set; }
    public string Answer { get; set; }
}
</code></pre>

<p>Now I make an ICollection of these available through an ObjectDataSource, and display them using a Repeater bound to the DataSource.  I use <strong>&lt;%#Eval("Question")%></strong> to display the Question, and I use a TextBox and <strong>&lt;%#Bind("Answer")%></strong> to accept an answer.</p>

<p>If my ObjectDataSource returns three Question objects, then my Repeater displays the three questions with a TextBox following each question for the user to provide an answer.</p>

<p>So far it works great.</p>

<p>Now I want to take the user's response and put it back into the relevant Question classes, which I will then persist.</p>

<p>Surely the framework should take care of all of this for me?  I've used the Bind method, I've specified a DataSourceID, I've specified an Update method in my ObjectDataSource class, but there seems no way to actually kickstart the whole thing.</p>

<p>I tried adding a Command button and in the code behind calling MyDataSource.Update(), but it attempts to call my Update method with no parameters, rather than the Question parameter it expects.</p>

<p>Surely there's an easy way to achieve all of this with little or no codebehind?</p>

<p>It seems like all the bits are there, but there's some glue missing to stick them all together.</p>

<p>Help!</p>

<p>Anthony</p>

[{'answer_id': 52513, 'author': 'Ben Scheirman', 'author_id': 3381, 'author_profile': 'https://Stackoverflow.com/users/3381', 'pm_score': 2, 'selected': True, 'text': '<p>You have to handle the postback event (button click or whatever) then enumerate the repeater items like this:</p>\n\n<pre><code>foreach(RepeaterItem item in rptQuestions.Items)\n{\n   //pull out question\n   var question = (Question)item.DataItem;\n   question.Answer = ((TextBox)item.FindControl("txtAnswer")).Text;\n\n   question.Save() ?  &lt;--- not sure what you want to do with it\n}\n</code></pre>\n'}, {'answer_id': 52639, 'author': 'littlecharva', 'author_id': 366, 'author_profile': 'https://Stackoverflow.com/users/366', 'pm_score': 0, 'selected': False, 'text': "<p>Then what's the point in the Bind method (as opposed to the Eval method) if I have to bind everything back up manually on postback?</p>\n"}, {'answer_id': 52725, 'author': 'Solmead', 'author_id': 2496, 'author_profile': 'https://Stackoverflow.com/users/2496', 'pm_score': 1, 'selected': False, 'text': "<p>The bind method really isn't for the repeater, it's more for the formview or gridview, where you are editing just one item in the list not every item in the list. </p>\n\n<p>On both you click a edit button which then gives you the bound controls (bound using bind) and then hit the save link which auto saves the item back into your datasource without any code behind.</p>\n"}, {'answer_id': 53722, 'author': 'littlecharva', 'author_id': 366, 'author_profile': 'https://Stackoverflow.com/users/366', 'pm_score': 0, 'selected': False, 'text': '<p>Ben: Having tried it, item.DataItem is always null, and according to the following post, it\'s not designed to be used that way:</p>\n\n<p><a href="http://www.netnewsgroups.net/group/microsoft.public.dotnet.framework.aspnet/topic4049.aspx" rel="nofollow noreferrer">http://www.netnewsgroups.net/group/microsoft.public.dotnet.framework.aspnet/topic4049.aspx</a></p>\n\n<p>So how on earth do I manually bind it back?</p>\n'}]
['https://Stackoverflow.com/questions/52485', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/366/']