I am developing an application for an online test. Currently, I have a gridview with 7 columns: 1 column for the question, 5 more columns for the possible answers, and then a textbox where the student will populate their answer. I would really like to remove the 5 answer columns from my gridview, and instead have one column that is a dropdownlist displaying the 5 potential answers for each question.
I work mostly with SQL and SSRS. I am a beginner with .net and C#.
For example: This code below, where I manually populate list items, works just fine. But my list items will change with each question, so I need to do it dynamically instead of hardcoding values in.
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList ID="ddlAnswers" runat="server">
<asp:ListItem Text ="Apple" Value = "A" ></asp:ListItem>
<asp:ListItem Text ="banana" Value = "b" ></asp:ListItem>
<asp:ListItem Text ="canary" Value = "c" ></asp:ListItem>
<asp:ListItem Text ="dairy" Value = "d" ></asp:ListItem>
<asp:ListItem Text ="elephant" Value = "e" ></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
Again, I am a beginner in .net, but is it possible to do something like what I've posted below?
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList ID="ddlAnswers" runat="server">
<asp:ListItem Value = "gridview1.columnC" ></asp:ListItem>
<asp:ListItem Value = "gridview1.ColumnD" ></asp:ListItem>
<asp:ListItem Value = "gridview1.ColumnE" ></asp:ListItem>
<asp:ListItem Value = "gridview1.ColumnF" ></asp:ListItem>
<asp:ListItem Value = "gridview1.ColumnB" ></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
Obviously, I know the syntax is wrong, but is it feasible to do this? Thanks very much!!