Click here to Skip to main content
15,041,788 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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 (The page I want to edit).

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

Image 1
Image 2
Image 3

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");

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

            DataTable tbl = new DataTable();


            DropDownDers.DataSource = tbl;

            DropDownDers.DataValueField = "DersAdi";

            //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))";
        //Butona basınca seçilen dersin öğrencilerinin gelmesi işlemi

       //Resim atama işlemini yapmadım

What I have tried:

I tried to change updatecommand of datasource when teacher clicks the "Kaydet" button.
Updated 25-Jun-21 6:55am
SeeSharp2 25-Jun-21 13:04pm
This is your code and you are in control. If you want the code to edit a different page then change the page. What's the problem?
Relmon 25-Jun-21 13:09pm
The problem is I want to update a database table. When I bind the table to gridview and try to edit button of GridView to update that table. The edit button automatically changes gridview table with another table. So I can't edit the table that I want (See images pls When I click edit, the table in the second image changes with the table in image 3 automatically so I can't update the table I want).
SeeSharp2 25-Jun-21 13:15pm
You are just repeating yourself. If the current code edits one table and you don't like that, change the code to edit the table you want. I don't follow what the problem is.
Relmon 25-Jun-21 13:21pm
Sorry if I can't be clear. I didn't wrote any code to edit the table. I am just using GridView's own edit column (I didn't assigned that button to edit any page). So I don't know how to change this. GridView's own edit column edits only one page. My question is : How can I make GridView's own edit column to edit the page I want.
SeeSharp2 25-Jun-21 13:31pm
From your screenshots, it looks like it is editing the same page. They all look the same.

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