Datatlist中的RadioButton [英] RadioButton in Datatlist

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

问题描述

我正在用C#在Asp.Net中开发一个应用程序(Quiz Engine).我有一个这样的数据库表.
QuestionId
问题
选项1
选项2
选项3
选项4
正确答案

1
你叫什么名字?
公羊
拉贾
拉克什
冉扬
公羊

2
什么是…..?
……….
……….
………………
…………………….
……………….


我想要的是检索这些数据并以问答"的形式显示给用户,并允许用户使用单选"按钮进行选择.我的问题是,无论我应该使用数据绑定控件(如DataList,Repeater还是Detail View中带有< Item Template>的单选按钮)的方式,如何显示此问题和答案.标签.如果是这样,那么如何维护页面状态(即用户选择的值)并将用户选择的值与正确答案进行比较.我还希望有一个标记为下一步"的按钮,以便当用户单击该按钮时,它应显示下一步问题和答案".我不知道该怎么做.如果有人知道,请帮助我提供代码.如果有人帮助我,我将不胜感激.

Hi, I am developing an application (Quiz Engine) in Asp.Net with C#. I have a database table like this.
QuestionId
Question
Option1
Option2
Option3
Option4
Correct Answer

1
What is your name?
Ram
Raja
Rakesh
Ranjan
Ram

2
What is …..?
……….
……….
……………
………………….
…………….


What I want is, to retrieve these data and display to the user as Question and Answer and enable the user to select with the Radio button. My problem is that how I can display this Question and Answer, whether I should use data bound controls like DataList, Repeater or Detail View with Radio Button inside the <Item Template> tag. And if it is so then how to maintain the state of the page (i.e. the value selected by the user) and compare the value selected by the user with the Correct Answer. I also want to have a button labeled ’Next’ so that when the User clicks on that button it should display the Next Question and Answer. I don’t know how to do that. If anybody knows Please help me with the code. I will be thankful if anybody helps me.

推荐答案

Replace your datalist with below designer code.

 <asp:DataList ID="DataList1" runat="server" CellPadding="4" ForeColor="#333333" OnItemDataBound="DataList1_ItemDataBound">
              <ItemTemplate>

                       <input id="rd" type="radio" name="rdGroup" value='<%# Eval("Chequedate") %>' ></input>
             </ItemTemplate>
  </asp:DataList>

Than you can get value of selected radio using Request.Form["rdGroup"] on click of a button.


这篇关于Datatlist中的RadioButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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