Click here to Skip to main content
16,018,802 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi ,
I'm currently working on an 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 ,

XML
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#
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();
        }


This isn't working, i dont know how to bind the 4 answers fields to the radiobuttonlist..
Posted
Updated 12-Jan-11 3:26am
v2
Comments
Dylan Morley 12-Jan-11 9:26am    
Code formatting

1 solution

Hope this[^]will give you an idea.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900