1
Good morning, everyone.
I need to create an online form that will have questions that will be inserted daily in each user’s profile. All questions are stored in a database along with their alternatives and correct answer.
Until then I can put everything right I bring the questions and mount the gridview with the radios button. However when saving the answers I need to pick the options dd Cad grid line 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 fill in 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 researches I made this code to check 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");
}
}
@bigown has some idea of another way that can be done or if this wrong this code?
– Diego Ferreira de Oliveira
I won’t touch it, but someone will come to help you soon.
– Maniero
I think it needs to be inserted into your gridview Onrowdatabound, so you can manipulate what’s inside it... Here is a guide explaining its function https://msdn.microsoft.com/pt-br/library/system.web.ui.webcontrols.gridview.onrowdatabound(v=vs.110). aspx
– Daniel Nicodemos