我的Gridview看起来像这样:
TimeSlotID
为 Datakey 。
这是一个时间表gridview数据。我想将其存储在数据库中。
表格行:
Timetable_ID slotID用于 Subject_Faculty TimeslotNumber 学期 平日
SlotID
表示StartTime和EndTime SlotID(StartTime and Endtime are being fetched from another database table)
TimeSlotNumber
表示当前行(例如:8:50-9:10的TimeslotNumber值 2 )。将从下面的下拉列表中提取Timetable_ID
和Semester
。
我的问题是如何将gridview数据存储到数据库
推荐链接: http://www.c-sharpcorner.com/Blogs/10923/insert-data-into-database-from-gridview-in-Asp-Net.aspx
但没有帮助,因为它可以保存行数据。我需要将其存储为blockwise(表示行+列)。但是gridview没有像GridviewColumn这样的属性。
GridView3.DataSource = dt2; //dt2 is for timeslots and datakey[SlotID]
GridView3.DataBind();
GridView3.Columns[2].Visible = false;
GridView3.Columns[3].Visible = false;
GridView3.Columns[4].Visible = false;
GridView3.Columns[5].Visible = false;
GridView3.Columns[6].Visible = false;
GridView3.Columns[7].Visible = false;
count = 1;
int branchID = ob.getBranchID(Convert.ToInt16(ddlschema.SelectedValue.ToString()));
DataTable dtsub = ob.getFacultySubject(branchID,Convert.ToInt16(DropDownList29.SelectedValue.ToString()));
dtsub.Columns.Add("Name", typeof(string), "Fname + ' ' + Lname + '--' + SubjectName ");
int temp22=0;
for (int gv3t1 = 0; gv3t1 < 6; gv3t1++)
{
if (weekday[gv3t1] == 1)
{
GridView3.Columns[gv3t1 + 2].Visible = true;
string name = "ddl" + gv3t1;
ddl[temp22] = name;
foreach (GridViewRow grdRow in GridView3.Rows)
{
bind_dropdownlist = (DropDownList)(GridView3.Rows[grdRow.RowIndex].Cells[gv3t1 + 2].FindControl(name));
bind_dropdownlist.DataTextField = "Name";
bind_dropdownlist.DataValueField = "ID";
bind_dropdownlist.DataSource = dtsub;
bind_dropdownlist.DataBind();
}
temp22++;
}
}