c# - 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.
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
}
解决方案
推荐阅读
- ms-word - 如何通过使用引用第二个单词文档的字段在单词文档中包含图像,而第二个单词文档又具有引用图像的字段?
- python - 如何选择正确的轮廓六位数组
- java - JUnit 5 和具有不同扩展的继承,用于使用 TestContainers 进行 Spring Boot 集成测试
- powershell - 如何使用 Powershell 更新现有的 csv 文件?
- python - 外部数据源无法识别从 Pandas 数据框导出的 csv 标题行
- ibm-doors - 是否可以从 DOORS 中的基线对象中获取模块?
- python - 如何在 vscode 中启用对 python 的代码镜头支持?
- ios - 带有状态值的编译器 SwiftUi 视图
- javascript - 如何按需要比较多个属性的另一个数组的对象的相同顺序对数组的对象进行排序?
- jmeter - 如何将属性或线程组变量传递给 sample_variables=