如何在gridview的行编辑事件中获取列值

时间:2013-08-16 11:14:20

标签: asp.net

这是我在rowdatabound事件中的编辑代码。

if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if ((e.Row.RowState & DataControlRowState.Edit) > 0)
                {
                    DropDownList dl = (DropDownList)e.Row.FindControl("Sectionname");
                    comp.MEDIUM = Convert.ToString(e.Row.FindControl("Medium"));
                    comp.CLASSNAME = Convert.ToString(e.Row.FindControl("ClassName"));
                    comp.ACADAMICYEAR = Convert.ToString(e.Row.FindControl("AcademicYear"));
                    DataTable worktype = inter.bindsectionforgird(comp);
                    dl.DataSource = worktype;
                    dl.DataTextField = "SectionName";
                    dl.DataValueField = "SectionId";
                    dl.DataBind();
                }
            }

我仍然无法获得这些字段的值。

1 个答案:

答案 0 :(得分:0)

我建议您在RowDataBound事件

中编写代码
  void GridView_RowDataBound(Object sender, GridViewRowEventArgs e)
 {

if(e.Row.RowType == DataControlRowType.DataRow)
   {
       // Write your code here           
   }

 }

您可以找到Grid的列

e.Row.FindControl("yourControlID")

您可以在中查看详细信息 MSDN reference 1
MSDN reference 2
CodeProject