我正在尝试通过以下代码添加数据:
protected void gridview1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (Session["BranchingCode"] != null)
{
List<CourseDetail> studentList = Course_Detail.GetStudentListOfBranch(Session["BranchingCode"].ToString(), Session["CurrentSession"].ToString());
if (studentList != null)
{
for (int i = 0; i < studentList.Count(); i++)
{
e.Row.Cells[0].Text = studentList[i].UserNameRoll;
e.Row.Cells[1].Text = studentList[i].StudentName;
}
}
}
GridView1.DataBind();
}
}
但由于没有datasource
附加到 Gridview,因此不会触发此事件。请告诉我该怎么办?无论如何要强行触发此事件或做其他事情并在其他地方输入数据..?