首页 > 解决方案 > Asp.net When I click "edit" button of GridView It automatically edits another table

问题描述

Teacher logins and selects which lecture it would like to update student's grades. When it clicks button, Gridview retrieves student infomations and grades. When teacher clicks GridView's edit button, GridView automatically editing the first table which loaded in "pageload". How can I edit the page I want? To visualize :

1- When page loaded normally

2- After selecting lecture and retrieving student informations

3- After clicking GridView's edit button. It edits wrong page. I want to edit the table in second image.

Please hit me up If you need any further informations.

When page loaded first.

After selecting lesson and retrieving it's student's infos

After Clicking edit button. Edits the wrong page.

protected void Page_Load(object sender, EventArgs e)
    {
        //Retrieving teacher's lectures from database to dropdownlist.

        //Sidebar kısmında isim ve numara labellarina verilerini atar
        UsernameLabel.Text = Session["UsernameSession"].ToString();
        UsernumberLabel.Text = Session["UsernumberSession"].ToString();

        //Dropdownlist içerisine giriş yapan öğretmenin derslerini çağırma işlemi
        if (!IsPostBack)
        {
            OleDbConnection baglanti = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/Users/ERKAN/Desktop/Sinav/Sinav/Veritaban.mdb");
            baglanti.Open();

            OleDbDataAdapter adptr2 = new OleDbDataAdapter("Select * FROM Dersler Where DersOgretmeni='" + UsernameLabel.Text + "'", baglanti);

            DataTable tbl = new DataTable();

            adptr2.Fill(tbl);

            DropDownDers.DataSource = tbl;

            DropDownDers.DataValueField = "DersAdi";
            DropDownDers.DataBind();
            baglanti.Close();
            baglanti.Dispose();


            //Dropdownlist içerisine dersleri çağırma işlemi

            //Gridview içerisine dersleri alan öğrencileri çağırma işlemi

        }

    }

    protected void Kaydet_Click(object sender, EventArgs e)
    {
       //Retvieving student informations from database to gridview.

        if (this.IsPostBack)
        {
           
            Veritabansource.SelectCommand = "Select [ID], [Ogrenciler], [OgrenciNotu] From "+DropDownDers.SelectedItem.ToString()+"";
            Veritabansource.DeleteCommand = "DELETE FROM [" + DropDownDers.SelectedItem.ToString() + "] WHERE [ID] = ? AND (([Ogrenciler] = ?) OR ([Ogrenciler] IS NULL AND ? IS NULL)) AND (([OgrenciNotu] = ?) OR ([OgrenciNotu] IS NULL AND ? IS NULL))";
            Veritabansource.UpdateCommand = "UPDATE["+DropDownDers.SelectedItem.ToString()+"] SET[Ogrenciler] = ?, [OgrenciNotu] = ? WHERE[ID] = ? AND(([Ogrenciler] = ?) OR([Ogrenciler] IS NULL AND ? IS NULL)) AND(([OgrenciNotu] = ?) OR([OgrenciNotu] IS NULL AND ? IS NULL))";
            Veritabansource.DataBind();
            GridView1.DataBind();
        }
        //Butona basınca seçilen dersin öğrencilerinin gelmesi işlemi

       //Resim atama işlemini yapmadım
    }

标签: c#asp.netgridview

解决方案


推荐阅读