Good morning everyone.
I need to create an online form that will have issues that will be entered daily into each user's profile. All questions are stored in a database along with their alternatives and correct answer.
So I can set everything right, I bring the questions and I mount the gridview with the radios button. However at the time of saving the answers I need to pick the dd dd grid line options and get which radio is selected.
Follow the form code:
<form id="form1" runat="server">
<div>
<asp:GridView ID="gridQuestoes" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField ="questao" HeaderText="questao" />
<asp:BoundField DataField ="Prioridade" HeaderText="Prioridade" />
<asp:TemplateField>
<ItemTemplate>
<asp:RadioButton ID="rbtSim" runat="server" Text="Sim" GroupName="users"/>
<asp:RadioButton ID="rbtNao" runat="server" Text="Não" GroupName="users"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<asp:Button ID="btnGravar" runat="server" Text="GRAVAR" OnClick="btnGravar_Click" />
</form>
Code used to populate GridView
BancoDeDados bd = new BancoDeDados();
List<Modelos.Questoes> lista = bd.listarQuestoes(1);
List<Quest1> listarQuest = new List<Quest1>();
foreach (Modelos.Questoes questoes in lista)
{
if (questoes.tipo == 1)
{
listarQuest.Add(new Quest1()
{
questao = questoes.questao,
prioridade = questoes.prioridade
});
}
}
gridQuestoes.DataSource = listarQuest;
gridQuestoes.DataBind();
In some searches I made this code to verify but it is not working
foreach (GridViewRow row in gridQuestoes.Rows)
{
BancoDeDados bd = new BancoDeDados();
RadioButton rb1 = row.FindControl("rbtSim") as RadioButton;
RadioButton rb2 = row.FindControl("rbtNao") as RadioButton;
if (rb1.Checked == true)
{
bd.gravar("Sim");
}
else if (rb2.Checked == true)
{
bd.gravar("Não");
}
}