I am creating a project called Online Exam Portal. In which Student can select Technology
and give exam. Student can select technology from dropdownlist.
Questions for particular Technology are coming from database. Now i want single question at a time in a view (of MultiView control), that is, when student clicks Next Button then only second question should be display in same view. I am able to retrieve one question but not ahead.
I have tried Following code:
ScheduleExam.Aspx :
<div class="col-md-6">
<div class="box-body">
<div class="form-group">
<asp:MultiView ID="mvExam" runat="server">
<asp:View ID="viewTech" runat="server">
<asp:DropDownList ID="ddlTechnology" runat="server" CssClass="form-control select2"></asp:DropDownList><br /><br />
<asp:Button ID="btnSchedule" Text="Schedule" CssClass="btn btn-primary" OnClick="btnSchedule_Click" runat="server" />
</asp:View>
<asp:View ID="viewTest" runat="server">
<asp:Label ID="lblQtnNum" runat="server"> </asp:Label><asp:Label ID="lblQuestion" runat="server"></asp:Label><br /><br />
<asp:RadioButton ID="rdbOpt1" runat="server" /><br />
<asp:RadioButton ID="rdbOpt2" runat="server" /><br />
<asp:RadioButton ID="rdbOpt3" runat="server" /><br /><br />
<asp:Button ID="btnNext" runat="server" CssClass="btn btn-primary" OnClick="btnNext_Click" Text="Next" />
</asp:View>
</asp:MultiView>
</div>
</div>
</div>
ScheduleExam.aspx.cs :
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
mvExam.ActiveViewIndex = 0;
using (dbDataContext dt = new dbDataContext())
{
var qry = from i in dt.Technologies
select i;
ddlTechnology.DataSource = qry;
ddlTechnology.DataTextField = "TechnologyName";
ddlTechnology.DataValueField = "TechnologyId";
ddlTechnology.DataBind();
ddlTechnology.Items.Insert(0, new ListItem("Select Technology", ""));
}
}
}
protected void btnSchedule_Click(object sender, EventArgs e)
{
using (dbDataContext dt = new dbDataContext())
{
var qry = from i in dt.Questions
where i.TechnologyId == ddlTechnology.SelectedIndex
select i;
Session["Question"] = qry.FirstOrDefault();
Session["Qt_Cnt"] = 1;
mvExam.ActiveViewIndex = 1;
foreach (var item in qry)
{
lblQtnNum.Text = Session["Qt_Cnt"].ToString();
lblQuestion.Text = item.Question1;
rdbOpt1.Text = item.Option1;
rdbOpt2.Text = item.Option2;
rdbOpt3.Text = item.Option3;
break;
}
}
}
I have searched on internet but couldn't find any fruitful results. Comment if any information lacking.
You can use Skip()
and Take()
on your query :
var qry = (from i in dt.Questions
where i.TechnologyId == ddlTechnology.SelectedIndex
select i).Skip(currentPage).Take(1);
Then you add the currentPage
variable to your class and increment it in the Next page button handler. And of course the Next page button handler must reexecute the code you have in the btnSchedule_Click
method.
Note that in my example currentPage
must be zero-based (first page is 0, not 1)