Hi ,
Am currently working on online examination web project.. i have a table like this..
sno question answer1 answer2 answer3 answer4 correctanswer
1 sql structured simple short none structured
i just want to bind these 4 answers to my radiobuttonlist which is present inside the gridview.. am not able to do that so please help me ....
here is what i've tried ,
Aspx code :
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText=" Online Test !">
<ItemTemplate>
<asp:Label ID="lbl_que" runat="server" Text='<%# Eval("questions") %>'
Height="16px" Width="800px"
Font-Size="X-Small"></asp:Label>
<br />
<asp:RadioButtonList ID="RadioButtonList6" runat="server" Font-Size="X-Small"
RepeatDirection="Horizontal" >
</asp:RadioButtonList>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txt_que_edit" runat="server" Text='<%# Bind("questions") %>'
Width="187px"></asp:TextBox>
</EditItemTemplate>
<ItemStyle HorizontalAlign="Left"></ItemStyle>
</asp:TemplateField>
C# code :
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
myConnection.Open();
cmd = new SqlCommand("select option1 , option2 , option3 , option4 from online where pn_BranchID = '" + employee.BranchId + "' and pn_questID='" + txt_qsetno.Text + "' ", myConnection);
rea1 = cmd.ExecuteReader();
if (rea1.Read())
{
RadioButtonList rbl_responses = (RadioButtonList)e.Row.Cells[1].FindControl("RadioButtonList6");
if (e.Row.RowType == DataControlRowType.DataRow)
{
rbl_responses.Items.Add(new ListItem(Convert.ToString(rea1["option1"])));
rbl_responses.Items.Add(new ListItem(Convert.ToString(rea1["option2"])));
rbl_responses.Items.Add(new ListItem(Convert.ToString(rea1["option3"])));
rbl_responses.Items.Add(new ListItem(Convert.ToString(rea1["option4"])));
}
rea1.Close();
myConnection.Close();
}
But its not working.. i dont know how to bind the 4 answers fields to the radiobuttonlist..