1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Problem with GridView, ListItem and RadiobuttonList in asp.net

Discussion in 'C#' started by rohansyco, Nov 17, 2010.

  1. #1
    Hi,,

    I m trying to create an online examination module which has to be very simple....

    But what i want to do is to store a large number of questions and to obtain on 25 questions from it randomly, so that no two persons logging in same time may have the same questions....

    then i just show all of them in a grid view..

    in grid view i add a label and a radio button list to show the questions and their qbjective options.....

    but the problem is that when i select the options and try to submit the selected index changed dramaticaaly other than the selection that we choose by our own...

    I m attaching the code of the page below...

    please review it ..

    and any help in this context is highly apprecuiated....


    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;

    public partial class Student_Panel_TakeExam : System.Web.UI.Page
    {
    Stud_Panel sp = new Stud_Panel();

    int sid, subid;
    DataSet ds, dsSession;
    protected void Page_Load(object sender, EventArgs e)
    {
    // sid = Convert.ToInt32(Session["SID"]);
    sid = 20; //THIS IS THE STUDENT ID JUST FOR TESTING
    //subid = Convert.ToInt32(Request.QueryString[0]);
    subid = 1; // THIS IS THE SUBJECT ID JUST FOR TESTING PURPOSE
    if (!IsPostBack)
    {

    Session["Question"] = sp.GetQuesForExams(subid); // THIS FUNCTION ALWAYS OBTAIN THE QUESTIONS IN RANDOM ORDER
    dsSession = (DataSet)Session["Question"]; // THIS IS TO PUT THE OBTAIND SHUFFLED QUESTIONS IN THE SESSION VARIABLE
    GridView1.DataSource = dsSession;
    GridView1.DataBind();

    for (int i = 0; i < dsSession.Tables[0].Rows.Count; i++)
    {
    Control ctrl = GridView1.Rows.Cells[0].FindControl("lblQues"); // I HAVE ADDED A LABEL IN TEMPLATE FIELD OF THE GRIDVIEW
    Label lblCtrl = ctrl as Label;
    lblCtrl.Text = "<h3>" + (i + 1).ToString() + ". " + dsSession.Tables[0].Rows["Question"].ToString() + ".<br></h3>";

    Control ctrl1 = GridView1.Rows.Cells[0].FindControl("rbl");
    RadioButtonList rblctrl = ctrl1 as RadioButtonList;

    int option = 3, ans = 5; // TO GET THE POSITIONS OF OPTIONS AND ANSWERS IN THE DATASET
    for (int j = 0; j < 4; j++)
    {
    ListItem li = new ListItem(); // CREATE A LIST VIEW AS TO POPULATE THE RADIOBUTTON LIST
    li.Text = dsSession.Tables[0].Rows[option].ToString();
    li.Value = dsSession.Tables[0].Rows[ans].ToString();
    //"<img src='30-02012010056.jpg' />";
    rblctrl.Items.Add(li);
    option = option + 3;
    ans = ans + 3;

    }
    }
    }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
    dsSession = (DataSet)Session["Question"];

    int count = 0;
    for (int i = 0; i < dsSession.Tables[0].Rows.Count; i++)
    {

    Control ctrl1 = GridView1.Rows.Cells[0].FindControl("rbl");
    RadioButtonList rblctrl = ctrl1 as RadioButtonList;
    Label1.Text += "<br>" + rblctrl.SelectedItem;
    }
    }
    }
     
    rohansyco, Nov 17, 2010 IP
  2. rohansyco

    rohansyco Member

    Messages:
    98
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #2
    please help me in the above problem.....
     
    rohansyco, Nov 17, 2010 IP