Question : Accessing controls in FormView

Hello I have a FormView on my webpage and there is a button on the form view. I have problems accessing the button from the code behind.

For other data controls (e.g. GridView), I'd get a row and in the row I'd find any particular control by its id or by its index. It doesn't work for the FormView. This button is not databound and I tried to access it from both Page_Load and from Data_Bound using all tricks I know, but alas I'm getting nowhere with it :(

I'm sure there should be a way to do it, and I'd aprpeciate if someone can help me to find it.

Thanks

Answer : Accessing controls in FormView

OK, I got it.
that's the final code:

protected void fvCurrentLoan_DataBound( object sender, EventArgs e )
{
      Button btnPayOff = ( Button )fvCurrentLoan.Controls[ 0 ].Controls[ 1 ].Controls[ 0 ].Controls[ 1 ].FindControl( "btnPayOff" );
      btnPayOff.Attributes.Add( "OnClick", "return confirm('" + Message.ConfirmPayOffLoan + "');" );
}

For curious minds, the first Controls[0] is a ChildTable, the second Controls[1] is FormViewRow, the third Controls[0] is a TableCell, and the last Controls[1] is an HtmlTable.

Ehehe, tricky one.
Thank you for your help, I'm closing this question.
Random Solutions  
 
programming4us programming4us