The grid is a good candidate for this sort of work. Let's assume your data
has a "QuestionId", and "Question" field, your datagrid would look something
like:
<asp
ataGrid id="grid" runat="server" DataKeyField="QuestionId"
AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="Question" />
<asp:TemplateColumn>
<ItemTemplate>
<asp:textbox ID="txt" Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp
ataGrid>
<asp:Button ID="Save" Runat="server" />
with a save button at the bottom. In your save button click code, you would
loop through each item of the grid and pull out the QuestionID (note that's
the DataKeyField of the grid) and the answer (which will be in teh control
"txt"):
For i As Integer = 0 To grid.Items.Count - 1
Dim item As DataGridItem = grid.Items(i)
Dim questionId As Integer = CInt(grid.DataKeys(item.ItemIndex))
Dim answerBox As TextBox = CType(item.FindControl("txt"), TextBox)
If Not answerBox Is Nothing Then
Dim answer As String = answerBox.Text
'SAVEANSWER(questionId, Answer)
End If
Next
Now, if you need to support more than just a textbox (ie, if that's dynamic
with the question), it gets a little more complicated. Basically, we'd add
a "TypeID" column to our data, we'd remove the textbox from our grid and put
a placeholder instead. Then, in the ItemDataBound event we'd do something
like:
Private Sub Grid_ItemDataBound(ByVal sender As Object, ByVal e As
DataGridItemEventArgs) Handles grid.ItemDataBound
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
ListItemType.AlternatingItem Then
Dim plc As PlaceHolder = CType(e.Item.FindControl("plc"),
PlaceHolder)
If Not plc Is Nothing Then
Dim dr As DataRowView = CType(e.Item.DataItem, DataRowView)
Select Case CInt(dr("type"))
Case 1
Dim txt As New TextBox
txt.Text = CStr(dr("value"))
plc.Controls.Add(txt)
Case 2
Dim ddl As New DropDownList
plc.Controls.Add(ddl)
End Select
End If
End If
End Sub
Hope that helps.
Karl