Şimdi Ara

İç İçe DataList Hesaplama

Daha Fazla
Bu Konudaki Kullanıcılar: Daha Az
2 Misafir - 2 Masaüstü
5 sn
3
Cevap
0
Favori
495
Tıklama
Daha Fazla
İstatistik
  • Konu İstatistikleri Yükleniyor
0 oy
Öne Çıkar
Sayfa: 1
Giriş
Mesaj
  • Merhaba arkadaslar. Datalist1 icinde 4 farkli ayri sonuc cikaran datalist kullandim.
    Cikan 4 sonucun ortalamasini hesaplamak istiyorum fakat hata aliyorum.

     İç İçe DataList Hesaplama



    protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {

    DataList DataList2 = (DataList)e.Item.FindControl("DataList2");
    DataList DataList4 = (DataList)e.Item.FindControl("DataList4");
    DataList DataList5 = (DataList)e.Item.FindControl("DataList5");
    DataList DataList6 = (DataList)e.Item.FindControl("DataList6");

    Label avgExam = (Label)DataList2.FindControl("lblExam");
    Label avgQuiz = (Label)DataList4.FindControl("lblQuiz");
    Label avgHomework = (Label)DataList5.FindControl("lblHomework");
    Label avgPerformance = (Label)DataList6.FindControl("lblPerformance");

    DataList DataList3 = (DataList)e.Item.FindControl("DataList3");

    Label sum = (Label)DataList3.FindControl("lblsum");

    int sayi1 = Convert.ToInt16(avgExam.Text);
    int sayi2 = Convert.ToInt16(avgQuiz.Text);
    int sayi3 = Convert.ToInt16(avgHomework.Text);
    int sayi4 = Convert.ToInt16(avgPerformance.Text);
    int ort = (sayi1 + sayi2 + sayi3 + sayi4) / 4;

    sum.Text = ort.ToString();

    }


    Aldigim hata su:

    Object reference not set to an instance of an object.
    int sayi1 = Convert.ToInt16(avgExam.Text);

    Bu konuda yardimci olabilirmisiniz? Tesekkur ederim.
     İç İçe DataList Hesaplama







  • Bunu da yazmamim bir faydasi olur belki.

     İç İçe DataList Hesaplama


    4 farkli Datalistte cikan sonuclari yaparken su kodlari kullandim :

    protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {

    DataRowView objRow = (DataRowView)e.Item.DataItem;
    DataList DataList2 = (DataList)e.Item.FindControl("DataList2");


    SqlCommand cmd = DBTools.Komut("Select Avg(Exam) as Average from Exams inner join Students on Students.StudentID = Exams.StudentID where Exams.StudentID=" + objRow["StudentID"].ToString() + " and CourseID=@CourseID and Students.ClassID=@ClassID and Students.BranchID=@BranchID and Semester=@Semester and Year=@Year and TeacherID=@TeacherID");


    cmd.Parameters.AddWithValue("@CourseID", DropDownList3.SelectedValue);
    cmd.Parameters.AddWithValue("@Year", ddlYear.SelectedValue);
    cmd.Parameters.AddWithValue("@Semester", cbsemester.SelectedValue);
    cmd.Parameters.AddWithValue("@TeacherID", Session["TeacherID"].ToString());
    cmd.Parameters.AddWithValue("@ClassID", DropDownList1.SelectedValue);
    cmd.Parameters.AddWithValue("@BranchID", DropDownList2.SelectedValue);

    cmd.Connection.Open();
    SqlDataReader dr = cmd.ExecuteReader();
    DataTable dt = new DataTable();
    dt.Load(dr);
    cmd.Connection.Close();
    DataList2.DataSource = dt;
    DataList2.DataBind();


    ////////////////////////////////////////////////////////////



    DataList DataList4 = (DataList)e.Item.FindControl("DataList4");
    DataList DataList5 = (DataList)e.Item.FindControl("DataList5");
    DataList DataList6 = (DataList)e.Item.FindControl("DataList6");

    Label avgExam = (Label)DataList2.FindControl("lblExam");
    Label avgQuiz = (Label)DataList4.FindControl("lblQuiz");
    Label avgHomework = (Label)DataList5.FindControl("lblHomework");
    Label avgPerformance = (Label)DataList6.FindControl("lblPerformance");

    DataList DataList3 = (DataList)e.Item.FindControl("DataList3");

    Label sum = (Label)DataList3.FindControl("lblsum");

    int sayi1 = Convert.ToInt16(avgExam.Text);
    int sayi2 = Convert.ToInt16(avgQuiz.Text);
    int sayi3 = Convert.ToInt16(avgHomework.Text);
    int sayi4 = Convert.ToInt16(avgPerformance.Text);
    int ort = (sayi1 + sayi2 + sayi3 + sayi4) / 4;

    sum.Text = ort.ToString();


    Aldigim hata su:

    Object reference not set to an instance of an object.
    int sayi1 = Convert.ToInt16(avgExam.Text);

    }



    < Bu mesaj 18.9.15 tarihinde kaybolan verilerden kurtarılmıştır >




  • Belki bunu da yazmamin bir faydasi olur.
    DataList icinde cikan sonuclari ayri ayri soyle yazdim:


     İç İçe DataList Hesaplama


    protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {
    DataRowView objRowAverageExam = (DataRowView)e.Item.DataItem;
    DataList DataList2 = (DataList)e.Item.FindControl("DataList2");


    SqlCommand cmdAverageExam = DBTools.Komut("Select Avg(Exam) as Average from Exams inner join Students on Students.StudentID = Exams.StudentID where Exams.StudentID=" + objRowAverageExam["StudentID"].ToString() + " and CourseID=@CourseID and Students.ClassID=@ClassID and Students.BranchID=@BranchID and Semester=@Semester and Year=@Year and TeacherID=@TeacherID");


    cmdAverageExam.Parameters.AddWithValue("@CourseID", DropDownList3.SelectedValue);
    cmdAverageExam.Parameters.AddWithValue("@Year", ddlYear.SelectedValue);
    cmdAverageExam.Parameters.AddWithValue("@Semester", cbsemester.SelectedValue);
    cmdAverageExam.Parameters.AddWithValue("@TeacherID", Session["TeacherID"].ToString());
    cmdAverageExam.Parameters.AddWithValue("@ClassID", DropDownList1.SelectedValue);
    cmdAverageExam.Parameters.AddWithValue("@BranchID", DropDownList2.SelectedValue);

    cmdAverageExam.Connection.Open();
    SqlDataReader drAverageExam = cmdAverageExam.ExecuteReader();
    DataTable dtAverageExam = new DataTable();
    dtAverageExam.Load(drAverageExam);
    cmdAverageExam.Connection.Close();
    DataList2.DataSource = dtAverageExam;
    DataList2.DataBind();


    //////////////////////////////////////////////////////////////////////////////


    DataList DataList4 = (DataList)e.Item.FindControl("DataList4");
    DataList DataList5 = (DataList)e.Item.FindControl("DataList5");
    DataList DataList6 = (DataList)e.Item.FindControl("DataList6");

    Label avgExam = (Label)DataList2.FindControl("lblExam");
    Label avgQuiz = (Label)DataList4.FindControl("lblQuiz");
    Label avgHomework = (Label)DataList5.FindControl("lblHomework");
    Label avgPerformance = (Label)DataList6.FindControl("lblPerformance");

    DataList DataList3 = (DataList)e.Item.FindControl("DataList3");

    Label sum = (Label)DataList3.FindControl("lblsum");

    int sayi1 = Convert.ToInt16(avgExam.Text);
    int sayi2 = Convert.ToInt16(avgQuiz.Text);
    int sayi3 = Convert.ToInt16(avgHomework.Text);
    int sayi4 = Convert.ToInt16(avgPerformance.Text);
    int ort = (sayi1 + sayi2 + sayi3 + sayi4) / 4;

    sum.Text = ort.ToString();

    }


    Aldigim hata su:

    Object reference not set to an instance of an object.
    int sayi1 = Convert.ToInt16(avgExam.Text);




  • Yapay Zeka’dan İlgili Konular
    Daha Fazla Göster
    
Sayfa: 1
- x
Bildirim
mesajınız kopyalandı (ctrl+v) yapıştırmak istediğiniz yere yapıştırabilirsiniz.