문제

I know how to get value the of a templatefield inside a RowDataBound event:

Control ctrl = e.Row.FindControl("Drop_Responsaveis");  
DropDownList ddl = ctrl as DropDownList;
ddl.items.add(something);

But I needto get it's value on a button_Click event... How May I do that?

Solution by the @Siz S answer

foreach (GridViewRow gvr in GridView1.Rows)
   {
     string str = ""
     Control ctrl = gvr.FindControl("Drop_Responsaveis");
     if (ctrl != null)
        {
           DropDownList ddl = ctrl as DropDownList;
           str= ddl.SelectedItem.ToString();
        }
    }
도움이 되었습니까?

해결책

you can get gridview TemplateField controls as

foreach (GridViewRow row in yourGrid.Rows)
{
     Control ctrl = row.FindControl("Drop_Responsaveis");
     DropDownList ddl = ctrl as DropDownList;
     ddl.items.add(something);
 }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top