测验演示编码 [英] quiz demo coding

查看:61
本文介绍了测验演示编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我目前正在从事在线考试网络项目..我有一个这样的表格..

sno问题answer1 answer2 answer3 answer4
正确答案
1 sql结构化简单简短没有结构化

我只想将这4个答案绑定到存在于gridview中的单选按钮列表中.无法执行此操作,所以请帮助我

这是我尝试过的,

 aspx代码:
<   asp:TemplateField     ItemStyle-Horizo​​ntalAlign   ="     HeaderText   =" 在线测试!" <   ItemTemplate  > 
                        <   asp:Label     ID   ="   runat   服务器" 文本  <%#Eval(" )
 
                                                 高度  ="  16像素" 宽度   800px" 
                                                 字体大小  ="  X-Small" <  /asp:标签 > 
                        <   br    > 
                        <   asp:RadioButtonList     ID   ="     ="  服务器" 字体大小  ="  
 
                                                  RepeatDirection   =" 水平"   > 
                        <  /asp:RadioButtonList  > 
                    <  /ItemTemplate  > 
                    <   EditItemTemplate  > 
                    <   asp:TextBox     ID   ="   runat   服务器" 文本  <%#Bind(" )
 
                                                 宽度  ="  187像素" <  /asp:TextBox  > 
                    <  /EditItemTemplate  > 

<   ItemStyle     ="  左侧" <   > 
                <  /asp:TemplateField  >  



 C#代码:
受保护的 无效 GridView1_RowDataBound(对象发​​件人,GridViewRowEventArgs e)
    {
            myConnection.Open();
            cmd =  SqlCommand("  + employee.BranchId +  '和pn_questID ='" + txt_qsetno.Text + " ,myConnection);
            rea1 = cmd.ExecuteReader();
            如果(rea1.Read())
            {
                RadioButtonList rbl_responses =(RadioButtonList)e.Row.Cells [ 1 ].FindControl("  RadioButtonList6");

                如果(例如,Row.RowType == DataControlRowType.DataRow)
                {
                    rbl_responses.Items.Add( ListItem(Convert.ToString(rea1 [" ]))));
                    rbl_responses.Items.Add( ListItem(Convert.ToString(rea1 [" ]))));
                    rbl_responses.Items.Add( ListItem(Convert.ToString(rea1 [" ]))));
                    rbl_responses.Items.Add( ListItem(Convert.ToString(rea1 [" ]))));
                }
            rea1.Close();
            myConnection.Close();
        } 



这不起作用,我不知道如何将4个答案字段绑定到单选按钮列表..

解决方案

希望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();
        }



This isn''t working, i dont know how to bind the 4 answers fields to the radiobuttonlist..

解决方案

Hope this[^]will give you an idea.


这篇关于测验演示编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆