Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
C#
partial class Default2 : System.Web.UI.Page
{

    int i;
    //int count =0;
	string ans= null;
    int[] a=new int[5];
	int t=0;
    SqlDataAdapter  adp= new SqlDataAdapter();
	DataSet ds = new DataSet();
	int ctr = 0;
    
	SqlConnection con = new SqlConnection("Data Source=Sraven\\SQLEXPRESS;Initial Catalog=ObjLogin;Integrated Security=True");
    DateTime mydate = default(DateTime);

	SqlCommand cmd = new SqlCommand();
	DataTable dt = new DataTable();

	DataRow dr = null;
	public void Show()
	{

        
        Session["Answered"] = dt;
		View v = this.View1;


		Label l = default(Label);
		l = (Label)v.FindControl("Label1");
        l.Text = dt.Rows[ctr]["Serial"] + ",";
		l = (Label)v.FindControl("Label2");
        dt.Rows[ctr]["question"] = l.Text; 

        //dt.Rows[ColumnName/ID][RowID] 
        

		RadioButtonList r = default(RadioButtonList);
		r = (RadioButtonList)v.FindControl("RadioButtonList1");
		r.Items.Clear();

        r.Items.Add(dt.Rows[ctr]["choice1"].ToString());
       r.Items.Add(dt.Rows[ctr]["choice1"].ToString());
       r.Items.Add(dt.Rows[ctr]["choice1"].ToString());
       r.Items.Add(dt.Rows[ctr]["choice3"].ToString());
       r.Items.Add(dt.Rows[ctr]["choice4"].ToString());
       dt.Rows[ctr]["selected"]=r.SelectedIndex;

        



		Session["ctr"] = ctr;
	}

    protected void Timer1_Tick1(object sender, EventArgs e)
    {
        //DateTime mydate = default(DateTime);
        DateTime mydate2 = DateTime.Now;
        DateTime mydate3 = default(DateTime);

        try
        {
            //TimeSpan DateDiff = DateTime.Parse(dr["IntervalEnd"].ToString()).Subtract(DateTime.Now);

            //TimeSpan DateDiff = DateTime.Parse(mydate.Subtract(mydate2));
            //mydate3 = mydate.Subtract(mydate2);
            mydate3 = DateTime.Parse(mydate.Subtract(mydate2).ToString());
            this.Label5.Text = "Time Left: " + mydate3.ToShortTimeString();
        }
        catch (Exception ex)
        {
            this.Label5.Text = "Error Setting up the Timer. Contact Admin";
        }


        if (mydate3.ToShortTimeString() == "00:00:00")
        {
            int marks = 0;
            Session["Answered"] = dt;

            foreach (DataRow  x in dt.Rows)
            {
                
                if (Convert.ToInt32(x["Selected"].ToString()) + 1 == Convert.ToInt32(x["correct"].ToString()))
                {
                    marks += 1;

                }
            }
            Response.Redirect("default3.aspx?marks=" + marks);

        }

        }

    protected void Page_Load(object sender, System.EventArgs e)
    {
        mydate = DateTime.Parse(Request.Cookies["start"].Value);
       



        if (!IsPostBack)
        {
            this.MultiView1.ActiveViewIndex = 0;
            con.Open();
            cmd.Connection = con;

            //Random arbit = new Random();
            ////VBMath.Randomize();
            
            Random randomNumber = new Random();
            randomNumber.Next();

        X:
            

            for (i = 0; i <= a.GetUpperBound(0); i++)
            {
                t = randomNumber.Next();

                

                if (Array.IndexOf(a, t) == -1)
                {
                    a[i] = t;

                }
                else
                {
                    goto X;
                }

            }


I got Error in this line l.Text = dt.Rows[ctr]["Serial"] + ",";

PLEASE CORRECT THIS CODE

ADVANCE THANK FOR YOUR REPLAY
Posted
Updated 19-Nov-11 6:57am
v2
Comments
thatraja 19-Nov-11 12:55pm    
what's the error message?
Smithers-Jones 19-Nov-11 13:53pm    
You don't have to shout.
edit: OP removed one of his comments, where he used all-caps and on which I was commenting. Now my comment looks like an answer to thatraja.
RaviRanjanKr 19-Nov-11 13:12pm    
Please be more specific while asking question. we need more information about your question.
Sergey Alexandrovich Kryukov 19-Nov-11 17:13pm    
This is not a question, so you cannot hope for answer, really. Explain what you wanted to do, where did you stuck, what's the problem, provide comprehensive issue report.
--SA

1 solution

l.Text = dt.Rows[ctr]["Serial"] + ",";

"INDEXOUTOFRANGE EXCEPTION WAS UNHANDLE BY THE USER CODE

THERE IS NO ROW POSITION 0(ZERE)"

The clue is in the error: There is no row in your table. You do not show where you load the table with anything other than a new table - so there are no rows. You will have to read some data into it at some point if you want to show any data from it...
 
Share this answer
 
Comments
OriginalGriff 20-Nov-11 5:05am    
Why are you telling me this? I did not suggest you should use an Item property, but that perhaps you should put some rows into your DataTable. You could (perhaps) read them from your database?

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