2013-08-16 31 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

相關問題