2013-08-16 28 views
0

这是我在rowdatabound事件中的编辑代码。如何在gridview的行编辑事件中获得列值

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(); 
       } 
      } 

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

+0

您在什么情况下编写了这段代码? – zey

+0

RowEditing事件 – baskaran

回答

0

我建议你写你的代码RowDataBound事件

void GridView_RowDataBound(Object sender, GridViewRowEventArgs e) 
{ 

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

} 

而且你可以在
MSDN reference 1
MSDN reference 2
CodeProject找到您的网格的行为

e.Row.FindControl("yourControlID") 

你可以看到详细

+0

是的,我编写了代码rowbound事件。但我仍然无法获得gridview的绑定字段的值。 – baskaran

+0

说清楚baskaran,'RowEditing'或'RowDataBound'? – zey

+0

首先我写了那些代码rowediting。然后将代码更改为rowdataboud事件。 – baskaran

相关问题