如何使用c#保存Gridview中每一行的Gridview [英] how to save Gridview each row in database using c#
问题描述
在Gridview记录如下
房间课程房间课程房间课程
11 EFA 21 RM 31
12 MFA 22 REO 32 CL2
13 33 PH2
14 MC 24 SAC 34
Roomallocation表设计如下(表格名称Roomallocation)
Roomno varchar(20)
课程varchar(20)
i希望从gridview中保存房间和课程
Roomno课程
11 EFA
12 MFA
14 MC
21 RM
22 REO
24 SAC
32 CL2
33 PH2
我怎么能用csharp。
Rgds,
Narasiman P.
In Gridview Records as follows
Room course Room course Room course
11 EFA 21 RM 31
12 MFA 22 REO 32 CL2
13 33 PH2
14 MC 24 SAC 34
Roomallocation table design as follows (table name Roomallocation)
Roomno varchar(20)
Course varchar(20)
i want to save the room and course from the gridview
Roomno Course
11 EFA
12 MFA
14 MC
21 RM
22 REO
24 SAC
32 CL2
33 PH2
for that how can i do using csharp.
Rgds,
Narasiman P.
推荐答案
使用followign for循环来获取每一行的单元格值...
use the followign for loop to get the cell values of each row...
foreach (DataGridViewRow row in dataGridView1.Rows)
{
MessageBox.Show(row.Cells[0].Value.ToString());
}
试试这个.. :)
Try this..:)
protected void button_Click(object s, EventArg e)
{
foreach (GridViewRow row in gvExportCourse.Rows)
{
Label exCourse = (Label)row.FindControl("gvlblCourseName");
Label exUniversityCourse = (Label)row.FindControl("gvlblUniversityCourseName");
//Add your Insert logic here...:)
}
label1.Text = "Course saved successfully.";
}
这篇关于如何使用c#保存Gridview中每一行的Gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!